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,190 @@
|
|
|
1
|
+
#import "NanoIconInlineBaseline.h"
|
|
2
|
+
#import "NanoIconView.h"
|
|
3
|
+
#import <React/RCTVersion.h>
|
|
4
|
+
#import <React/RCTViewComponentView.h>
|
|
5
|
+
#import <react/renderer/textlayoutmanager/RCTAttributedTextUtils.h>
|
|
6
|
+
#import <objc/runtime.h>
|
|
7
|
+
#import <vector>
|
|
8
|
+
|
|
9
|
+
// RN <= 0.81 puts an inline view's bottom exactly on the text baseline.
|
|
10
|
+
// Since 0.82 (facebook/react-native#53341) the frame is `line bottom + descender
|
|
11
|
+
// of the attachment run's font`, and that run only carries the NSTextStorage
|
|
12
|
+
// default font, so the view lands below the baseline by an amount that
|
|
13
|
+
// depends on the text's font size and lineHeight.
|
|
14
|
+
static BOOL NanoIconReactNativePlacesInlineViewsOffBaseline(void) {
|
|
15
|
+
static BOOL result;
|
|
16
|
+
static dispatch_once_t once;
|
|
17
|
+
dispatch_once(&once, ^{
|
|
18
|
+
NSDictionary *version = RCTGetReactNativeVersion();
|
|
19
|
+
NSInteger major = [version[RCTVersionMajor] integerValue];
|
|
20
|
+
NSInteger minor = [version[RCTVersionMinor] integerValue];
|
|
21
|
+
result = major > 0 || minor >= 82;
|
|
22
|
+
});
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// The paragraph view is the direct superview of an inline icon; a couple of
|
|
27
|
+
// extra levels cover wrappers RN may insert. nil for standalone icons and on
|
|
28
|
+
// RN <= 0.81, so those never pay for a layout.
|
|
29
|
+
static void NanoIconInstallParagraphUpdateHook(Class paragraphClass);
|
|
30
|
+
|
|
31
|
+
UIView *NanoIconParagraphNeedingBaselineCorrection(UIView *view) {
|
|
32
|
+
if (!NanoIconReactNativePlacesInlineViewsOffBaseline()) return nil;
|
|
33
|
+
UIView *current = view.superview;
|
|
34
|
+
for (int depth = 0; depth < 3 && current; depth++) {
|
|
35
|
+
if ([NSStringFromClass([current class]) isEqualToString:@"RCTParagraphComponentView"]) {
|
|
36
|
+
NanoIconInstallParagraphUpdateHook([current class]);
|
|
37
|
+
return current;
|
|
38
|
+
}
|
|
39
|
+
current = current.superview;
|
|
40
|
+
}
|
|
41
|
+
return nil;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Text is laid out inside the paragraph's content frame (bounds minus
|
|
45
|
+
// padding). RCTViewComponentView keeps it in a protected ivar.
|
|
46
|
+
static CGRect NanoIconContentFrame(UIView *paragraph) {
|
|
47
|
+
static Ivar ivar = class_getInstanceVariable([RCTViewComponentView class], "_layoutMetrics");
|
|
48
|
+
if (ivar) {
|
|
49
|
+
const auto &metrics = *reinterpret_cast<const facebook::react::LayoutMetrics *>(
|
|
50
|
+
reinterpret_cast<const uint8_t *>((__bridge const void *)paragraph) + ivar_getOffset(ivar));
|
|
51
|
+
facebook::react::Rect content = metrics.getContentFrame();
|
|
52
|
+
if (content.size.width > 0 && content.size.height > 0) {
|
|
53
|
+
return CGRectMake(content.origin.x, content.origin.y, content.size.width, content.size.height);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return paragraph.bounds;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@interface NanoIconParagraphBaselines : NSObject
|
|
60
|
+
@property (nonatomic, readonly) std::vector<CGPoint> &entries;
|
|
61
|
+
@end
|
|
62
|
+
|
|
63
|
+
@implementation NanoIconParagraphBaselines {
|
|
64
|
+
std::vector<CGPoint> _entries;
|
|
65
|
+
}
|
|
66
|
+
- (std::vector<CGPoint> &)entries { return _entries; }
|
|
67
|
+
@end
|
|
68
|
+
|
|
69
|
+
static const void *kNanoIconParagraphBaselinesKey = &kNanoIconParagraphBaselinesKey;
|
|
70
|
+
|
|
71
|
+
static void NanoIconInvalidateIconsIn(UIView *view, int depth) {
|
|
72
|
+
for (UIView *child in view.subviews) {
|
|
73
|
+
if ([child isKindOfClass:[NanoIconView class]]) {
|
|
74
|
+
[(NanoIconView *)child invalidateInlineBaseline];
|
|
75
|
+
} else if (depth > 1) {
|
|
76
|
+
NanoIconInvalidateIconsIn(child, depth - 1);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// A text change that keeps an icon's frame (same line bottom, different font
|
|
82
|
+
// or lineHeight) still moves the baseline, and RN only notifies children whose
|
|
83
|
+
// layout changed. The paragraph's state update is the one signal that covers
|
|
84
|
+
// every text change, so its icons are invalidated from there.
|
|
85
|
+
static void NanoIconInstallParagraphUpdateHook(Class paragraphClass) {
|
|
86
|
+
static dispatch_once_t once;
|
|
87
|
+
dispatch_once(&once, ^{
|
|
88
|
+
SEL selector = @selector(updateState:oldState:);
|
|
89
|
+
Method method = class_getInstanceMethod(paragraphClass, selector);
|
|
90
|
+
if (!method) return;
|
|
91
|
+
using StateRef = const facebook::react::State::Shared &;
|
|
92
|
+
auto original = reinterpret_cast<void (*)(id, SEL, StateRef, StateRef)>(method_getImplementation(method));
|
|
93
|
+
IMP hooked = imp_implementationWithBlock(^(UIView *paragraph, StateRef state, StateRef oldState) {
|
|
94
|
+
original(paragraph, selector, state, oldState);
|
|
95
|
+
objc_setAssociatedObject(paragraph, kNanoIconParagraphBaselinesKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
96
|
+
NanoIconInvalidateIconsIn(paragraph, 3);
|
|
97
|
+
});
|
|
98
|
+
method_setImplementation(method, hooked);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Lays the paragraph out again the way RCTTextLayoutManager does (same
|
|
103
|
+
// container settings and lineHeight baseline offset) and records where TextKit
|
|
104
|
+
// put the baseline of every attachment. Layout stops after the last attachment.
|
|
105
|
+
static NanoIconParagraphBaselines *NanoIconLayOutBaselines(UIView *paragraph, NSAttributedString *text) {
|
|
106
|
+
CGRect content = NanoIconContentFrame(paragraph);
|
|
107
|
+
NSTextContainer *container = [[NSTextContainer alloc] initWithSize:content.size];
|
|
108
|
+
container.lineFragmentPadding = 0;
|
|
109
|
+
container.lineBreakMode = NSLineBreakByClipping;
|
|
110
|
+
NSLayoutManager *layoutManager = [NSLayoutManager new];
|
|
111
|
+
layoutManager.usesFontLeading = NO;
|
|
112
|
+
[layoutManager addTextContainer:container];
|
|
113
|
+
NSTextStorage *storage = [[NSTextStorage alloc] initWithAttributedString:text];
|
|
114
|
+
RCTApplyBaselineOffset(storage);
|
|
115
|
+
[storage addLayoutManager:layoutManager];
|
|
116
|
+
|
|
117
|
+
__block NSUInteger lastAttachmentEnd = 0;
|
|
118
|
+
[storage enumerateAttribute:NSAttachmentAttributeName
|
|
119
|
+
inRange:NSMakeRange(0, storage.length)
|
|
120
|
+
options:0
|
|
121
|
+
usingBlock:^(NSTextAttachment *attachment, NSRange range, __unused BOOL *stop) {
|
|
122
|
+
if (attachment) lastAttachmentEnd = NSMaxRange(range);
|
|
123
|
+
}];
|
|
124
|
+
if (lastAttachmentEnd == 0) return nil;
|
|
125
|
+
[layoutManager ensureLayoutForCharacterRange:NSMakeRange(0, lastAttachmentEnd)];
|
|
126
|
+
|
|
127
|
+
NanoIconParagraphBaselines *baselines = [NanoIconParagraphBaselines new];
|
|
128
|
+
std::vector<CGPoint> &entries = baselines.entries;
|
|
129
|
+
[storage enumerateAttribute:NSAttachmentAttributeName
|
|
130
|
+
inRange:NSMakeRange(0, lastAttachmentEnd)
|
|
131
|
+
options:0
|
|
132
|
+
usingBlock:^(NSTextAttachment *attachment, NSRange range, __unused BOOL *stop) {
|
|
133
|
+
if (!attachment) return;
|
|
134
|
+
NSUInteger glyphIndex = [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:NULL].location;
|
|
135
|
+
CGRect line = [layoutManager lineFragmentRectForGlyphAtIndex:glyphIndex effectiveRange:NULL];
|
|
136
|
+
CGPoint location = [layoutManager locationForGlyphAtIndex:glyphIndex];
|
|
137
|
+
entries.push_back(CGPointMake(content.origin.x + location.x,
|
|
138
|
+
content.origin.y + line.origin.y + location.y));
|
|
139
|
+
}];
|
|
140
|
+
return baselines;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// One layout per paragraph per layout pass: the result is kept on the
|
|
144
|
+
// paragraph view until the next main-queue turn so sibling icons reuse it.
|
|
145
|
+
static NanoIconParagraphBaselines *NanoIconBaselinesForParagraph(UIView *paragraph) {
|
|
146
|
+
NanoIconParagraphBaselines *cached = objc_getAssociatedObject(paragraph, kNanoIconParagraphBaselinesKey);
|
|
147
|
+
if (cached) return cached;
|
|
148
|
+
|
|
149
|
+
NSAttributedString *text = nil;
|
|
150
|
+
if ([paragraph respondsToSelector:@selector(attributedText)]) {
|
|
151
|
+
text = [paragraph performSelector:@selector(attributedText)];
|
|
152
|
+
}
|
|
153
|
+
if (text.length == 0) return nil;
|
|
154
|
+
|
|
155
|
+
NanoIconParagraphBaselines *baselines = NanoIconLayOutBaselines(paragraph, text);
|
|
156
|
+
if (!baselines) return nil;
|
|
157
|
+
|
|
158
|
+
objc_setAssociatedObject(paragraph, kNanoIconParagraphBaselinesKey, baselines, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
159
|
+
__weak UIView *weakParagraph = paragraph;
|
|
160
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
161
|
+
UIView *strongParagraph = weakParagraph;
|
|
162
|
+
if (strongParagraph) {
|
|
163
|
+
objc_setAssociatedObject(strongParagraph, kNanoIconParagraphBaselinesKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
return baselines;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Distance from the view's bottom edge down to the baseline RN meant it to
|
|
170
|
+
// sit on, rounded to the pixel grid. The attachment is matched by x; the
|
|
171
|
+
// nearest baseline resolves lines that start at the same x.
|
|
172
|
+
CGFloat NanoIconInlineBaselineOffset(UIView *view, UIView *paragraph) {
|
|
173
|
+
NanoIconParagraphBaselines *baselines = NanoIconBaselinesForParagraph(paragraph);
|
|
174
|
+
if (!baselines) return 0;
|
|
175
|
+
|
|
176
|
+
CGRect frame = [view.superview convertRect:view.frame toView:paragraph];
|
|
177
|
+
CGFloat bottom = CGRectGetMaxY(frame);
|
|
178
|
+
CGFloat nearest = bottom;
|
|
179
|
+
CGFloat nearestDistance = CGFLOAT_MAX;
|
|
180
|
+
for (const CGPoint &baseline : baselines.entries) {
|
|
181
|
+
if (fabs(baseline.x - frame.origin.x) > 1.5) continue;
|
|
182
|
+
CGFloat distance = fabs(baseline.y - bottom);
|
|
183
|
+
if (distance < nearestDistance) {
|
|
184
|
+
nearestDistance = distance;
|
|
185
|
+
nearest = baseline.y;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
CGFloat scale = [UIScreen mainScreen].scale;
|
|
189
|
+
return round((bottom - nearest) * scale) / scale;
|
|
190
|
+
}
|
package/ios/NanoIconView.h
CHANGED
package/ios/NanoIconView.mm
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
#import <CoreText/CoreText.h>
|
|
4
4
|
#import <React/RCTConversions.h>
|
|
5
5
|
#import <React/RCTFabricComponentsPlugins.h>
|
|
6
|
-
#import <react/renderer/components/RNNanoIconsSpec/
|
|
6
|
+
#import <react/renderer/components/RNNanoIconsSpec/NanoIconViewComponentDescriptor.h>
|
|
7
7
|
#import <react/renderer/components/RNNanoIconsSpec/Props.h>
|
|
8
|
+
#import "NanoIconInlineBaseline.h"
|
|
8
9
|
|
|
9
10
|
using namespace facebook::react;
|
|
10
11
|
|
|
@@ -50,18 +51,22 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
|
|
|
50
51
|
NSString *_fontFamily;
|
|
51
52
|
CGFloat _fontSize;
|
|
52
53
|
std::vector<CGGlyph> _glyphs;
|
|
53
|
-
|
|
54
|
+
// Unresolved layer colors — may be trait-dependent (DynamicColorIOS, PlatformColor).
|
|
55
|
+
NSArray<UIColor *> *_layerColors;
|
|
56
|
+
// _layerColors resolved against the current trait collection.
|
|
54
57
|
std::vector<CGColorRef> _cachedCGColors;
|
|
58
|
+
UIColor *_tintColor;
|
|
59
|
+
CGColorRef _cachedTintCGColor;
|
|
60
|
+
std::vector<bool> _tintable;
|
|
55
61
|
CGFloat _fitScale;
|
|
56
62
|
CGPoint _baselinePosition;
|
|
57
63
|
BOOL _metricsValid;
|
|
58
64
|
|
|
59
65
|
// Inline-in-Text detection — resolved once on first layout, cached until reparenting.
|
|
60
66
|
// Standalone icons (vast majority) skip the superview walk entirely after detection.
|
|
61
|
-
BOOL
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
CGFloat _cachedBaselineOffset;
|
|
67
|
+
BOOL _paragraphResolved;
|
|
68
|
+
UIView * __weak _paragraph;
|
|
69
|
+
CGFloat _baselineOffset;
|
|
65
70
|
BOOL _baselineOffsetValid;
|
|
66
71
|
|
|
67
72
|
// Drawing sublayer for inline icons — provides a shifted pixel buffer so the
|
|
@@ -112,61 +117,19 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
|
|
|
112
117
|
_metricsValid = YES;
|
|
113
118
|
}
|
|
114
119
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// ObjC runtime method resolution or attributed string reads.
|
|
120
|
-
- (void)_detectAndCacheInlineState {
|
|
121
|
-
_inlineDetected = YES;
|
|
122
|
-
_isInlineInText = NO;
|
|
123
|
-
_paragraphView = nil;
|
|
124
|
-
_cachedBaselineOffset = 0;
|
|
125
|
-
_baselineOffsetValid = YES;
|
|
126
|
-
|
|
127
|
-
// RCTParagraphComponentView is the immediate or near-immediate parent
|
|
128
|
-
// when the icon is inside <Text>. Three levels covers all known layouts.
|
|
129
|
-
UIView *current = self.superview;
|
|
130
|
-
UIView *target = nil;
|
|
131
|
-
for (int i = 0; i < 3 && current; i++) {
|
|
132
|
-
if ([NSStringFromClass([current class]) isEqualToString:@"RCTParagraphComponentView"]) {
|
|
133
|
-
target = current;
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
current = current.superview;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (!target) return;
|
|
120
|
+
- (void)invalidateInlineBaseline {
|
|
121
|
+
_baselineOffsetValid = NO;
|
|
122
|
+
[self setNeedsLayout];
|
|
123
|
+
}
|
|
140
124
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
125
|
+
// The baseline offset depends on where RN placed the view, so a new frame
|
|
126
|
+
// invalidates it.
|
|
127
|
+
- (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics
|
|
128
|
+
oldLayoutMetrics:(const LayoutMetrics &)oldLayoutMetrics {
|
|
129
|
+
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
|
|
130
|
+
if (layoutMetrics.frame != oldLayoutMetrics.frame) {
|
|
131
|
+
_baselineOffsetValid = NO;
|
|
144
132
|
}
|
|
145
|
-
if (!attrStr || attrStr.length == 0) return;
|
|
146
|
-
|
|
147
|
-
UIFont *f = [attrStr attribute:NSFontAttributeName atIndex:0 effectiveRange:nil];
|
|
148
|
-
if (!f) return;
|
|
149
|
-
|
|
150
|
-
_isInlineInText = YES;
|
|
151
|
-
_paragraphView = target;
|
|
152
|
-
|
|
153
|
-
// Derive the distance from this view's bottom edge to the text baseline.
|
|
154
|
-
// Respects custom RN lineHeight (mapped to NSParagraphStyle.maximumLineHeight)
|
|
155
|
-
// and any baseline offset applied by Fabric's text layout.
|
|
156
|
-
NSParagraphStyle *style = [attrStr attribute:NSParagraphStyleAttributeName
|
|
157
|
-
atIndex:0 effectiveRange:nil];
|
|
158
|
-
CGFloat lineHeight = (style && style.maximumLineHeight > 0)
|
|
159
|
-
? style.maximumLineHeight : f.lineHeight;
|
|
160
|
-
|
|
161
|
-
NSNumber *bOff = [attrStr attribute:NSBaselineOffsetAttributeName
|
|
162
|
-
atIndex:0 effectiveRange:nil];
|
|
163
|
-
CGFloat baselineFromLineTop = f.ascender - (bOff ? bOff.doubleValue : 0);
|
|
164
|
-
|
|
165
|
-
CGFloat frameBottom = self.frame.origin.y + self.frame.size.height;
|
|
166
|
-
CGFloat posInLine = fmod(frameBottom, lineHeight);
|
|
167
|
-
if (posInLine < 0.01) posInLine = lineHeight;
|
|
168
|
-
|
|
169
|
-
_cachedBaselineOffset = MAX(0, posInLine - baselineFromLineTop);
|
|
170
133
|
}
|
|
171
134
|
|
|
172
135
|
// Lazily create the drawing sublayer for inline-in-Text icons.
|
|
@@ -185,17 +148,12 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
|
|
|
185
148
|
// Reset inline state when the view moves to a new parent.
|
|
186
149
|
- (void)didMoveToSuperview {
|
|
187
150
|
[super didMoveToSuperview];
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
_paragraphView = nil;
|
|
151
|
+
_paragraphResolved = NO;
|
|
152
|
+
_paragraph = nil;
|
|
191
153
|
_baselineOffsetValid = NO;
|
|
192
|
-
if (_drawingLayer) {
|
|
193
|
-
[_drawingLayer removeFromSuperlayer];
|
|
194
|
-
_drawingLayer = nil;
|
|
195
|
-
}
|
|
196
154
|
}
|
|
197
155
|
|
|
198
|
-
//
|
|
156
|
+
// _baselineOffset and _fitScale are both derived from bounds.
|
|
199
157
|
- (void)setBounds:(CGRect)bounds {
|
|
200
158
|
if (!CGSizeEqualToSize(self.bounds.size, bounds.size)) {
|
|
201
159
|
_baselineOffsetValid = NO;
|
|
@@ -206,43 +164,49 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
|
|
|
206
164
|
|
|
207
165
|
#pragma mark - Layout
|
|
208
166
|
|
|
209
|
-
// Standalone: no work beyond metrics validation (drawing via drawRect: on self).
|
|
210
|
-
// Inline: position the drawing sublayer with the cached baseline offset,
|
|
211
|
-
// recomputing only when bounds change or the view is reparented.
|
|
212
167
|
- (void)layoutSubviews {
|
|
213
168
|
[super layoutSubviews];
|
|
214
169
|
if (!_metricsValid) [self _updateMetrics];
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
170
|
+
if (!_paragraphResolved) {
|
|
171
|
+
_paragraph = NanoIconParagraphNeedingBaselineCorrection(self);
|
|
172
|
+
_paragraphResolved = YES;
|
|
173
|
+
}
|
|
174
|
+
if (!_baselineOffsetValid) {
|
|
175
|
+
_baselineOffset = _paragraph ? NanoIconInlineBaselineOffset(self, _paragraph) : 0;
|
|
176
|
+
_baselineOffsetValid = YES;
|
|
218
177
|
}
|
|
178
|
+
[self _layoutDrawingLayer];
|
|
179
|
+
}
|
|
219
180
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
[CATransaction begin];
|
|
230
|
-
[CATransaction setDisableActions:YES];
|
|
231
|
-
_drawingLayer.frame = newFrame;
|
|
232
|
-
[CATransaction commit];
|
|
181
|
+
// Standalone icons draw in drawRect:. An icon that needs a baseline correction
|
|
182
|
+
// draws in a sublayer shifted by the offset instead, so it can overflow the
|
|
183
|
+
// Yoga frame without moving the view itself.
|
|
184
|
+
- (void)_layoutDrawingLayer {
|
|
185
|
+
if (_baselineOffset == 0) {
|
|
186
|
+
if (_drawingLayer) {
|
|
187
|
+
[_drawingLayer removeFromSuperlayer];
|
|
188
|
+
_drawingLayer = nil;
|
|
189
|
+
[self setNeedsDisplay];
|
|
233
190
|
}
|
|
234
|
-
|
|
235
|
-
// setNeedsDisplay from updateProps (which targeted self before detection).
|
|
236
|
-
if (created) [_drawingLayer setNeedsDisplay];
|
|
191
|
+
return;
|
|
237
192
|
}
|
|
238
|
-
|
|
193
|
+
BOOL created = !_drawingLayer;
|
|
194
|
+
[self _ensureDrawingLayer];
|
|
195
|
+
CGRect frame = CGRectMake(0, -_baselineOffset, self.bounds.size.width, self.bounds.size.height);
|
|
196
|
+
if (!CGRectEqualToRect(_drawingLayer.frame, frame)) {
|
|
197
|
+
[CATransaction begin];
|
|
198
|
+
[CATransaction setDisableActions:YES];
|
|
199
|
+
_drawingLayer.frame = frame;
|
|
200
|
+
[CATransaction commit];
|
|
201
|
+
}
|
|
202
|
+
if (created) [_drawingLayer setNeedsDisplay];
|
|
239
203
|
}
|
|
240
204
|
|
|
241
205
|
#pragma mark - Drawing
|
|
242
206
|
|
|
243
207
|
// Standalone icons draw directly in this view's drawRect:.
|
|
244
208
|
- (void)drawRect:(CGRect)rect {
|
|
245
|
-
if (
|
|
209
|
+
if (_drawingLayer) return;
|
|
246
210
|
CGContextRef ctx = UIGraphicsGetCurrentContext();
|
|
247
211
|
if (ctx) [self _drawIconInContext:ctx bounds:self.bounds];
|
|
248
212
|
}
|
|
@@ -263,7 +227,7 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
|
|
|
263
227
|
while (i < _glyphs.size()) {
|
|
264
228
|
if (_glyphs[i] == 0) { i++; continue; }
|
|
265
229
|
|
|
266
|
-
CGColorRef color =
|
|
230
|
+
CGColorRef color = [self _colorForLayer:i];
|
|
267
231
|
if (!color) {
|
|
268
232
|
static CGColorRef sBlack = CGColorCreateSRGB(0, 0, 0, 1);
|
|
269
233
|
color = sBlack;
|
|
@@ -278,7 +242,7 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
|
|
|
278
242
|
|
|
279
243
|
while (i < _glyphs.size()) {
|
|
280
244
|
if (_glyphs[i] == 0) { i++; continue; }
|
|
281
|
-
CGColorRef next =
|
|
245
|
+
CGColorRef next = [self _colorForLayer:i];
|
|
282
246
|
if (i > batchStart && next != color) break;
|
|
283
247
|
if (batchCount < 16) {
|
|
284
248
|
posBuf[batchCount] = _baselinePosition;
|
|
@@ -318,19 +282,34 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
|
|
|
318
282
|
- (void)_releaseCachedColors {
|
|
319
283
|
for (CGColorRef c : _cachedCGColors) CGColorRelease(c);
|
|
320
284
|
_cachedCGColors.clear();
|
|
285
|
+
if (_cachedTintCGColor) {
|
|
286
|
+
CGColorRelease(_cachedTintCGColor);
|
|
287
|
+
_cachedTintCGColor = NULL;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
- (CGColorRef)_colorForLayer:(size_t)index {
|
|
292
|
+
if (_cachedTintCGColor && index < _tintable.size() && _tintable[index]) {
|
|
293
|
+
return _cachedTintCGColor;
|
|
294
|
+
}
|
|
295
|
+
return index < _cachedCGColors.size() ? _cachedCGColors[index] : NULL;
|
|
321
296
|
}
|
|
322
297
|
|
|
323
|
-
//
|
|
298
|
+
// Resolve the layer colors against the current traits into cached CGColorRefs.
|
|
299
|
+
// Resolving up front (rather than relying on UIKit's current trait collection at
|
|
300
|
+
// draw time) keeps the CALayer inline-in-Text path correct — CoreAnimation does
|
|
301
|
+
// not install a trait collection around -drawInContext:.
|
|
324
302
|
- (void)_rebuildCachedColors {
|
|
325
303
|
[self _releaseCachedColors];
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
304
|
+
UITraitCollection *traits = self.traitCollection;
|
|
305
|
+
_cachedCGColors.resize(_layerColors.count);
|
|
306
|
+
for (NSUInteger i = 0; i < _layerColors.count; i++) {
|
|
307
|
+
UIColor *resolved = [_layerColors[i] resolvedColorWithTraitCollection:traits];
|
|
308
|
+
_cachedCGColors[i] = CGColorRetain(resolved.CGColor);
|
|
309
|
+
}
|
|
310
|
+
if (_tintColor) {
|
|
311
|
+
UIColor *resolved = [_tintColor resolvedColorWithTraitCollection:traits];
|
|
312
|
+
_cachedTintCGColor = CGColorRetain(resolved.CGColor);
|
|
334
313
|
}
|
|
335
314
|
}
|
|
336
315
|
|
|
@@ -342,9 +321,9 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
|
|
|
342
321
|
BOOL needsRedraw = NO;
|
|
343
322
|
|
|
344
323
|
if (oldViewProps.fontFamily != newViewProps.fontFamily ||
|
|
345
|
-
oldViewProps.
|
|
324
|
+
oldViewProps.size != newViewProps.size) {
|
|
346
325
|
_fontFamily = [NSString stringWithUTF8String:newViewProps.fontFamily.c_str()];
|
|
347
|
-
_fontSize = newViewProps.
|
|
326
|
+
_fontSize = newViewProps.size;
|
|
348
327
|
_font = NanoIconResolveFont(_fontFamily, _fontSize);
|
|
349
328
|
_metricsValid = NO;
|
|
350
329
|
fontChanged = YES;
|
|
@@ -359,14 +338,31 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
|
|
|
359
338
|
|
|
360
339
|
if (oldViewProps.colors != newViewProps.colors) {
|
|
361
340
|
const auto &colors = newViewProps.colors;
|
|
362
|
-
|
|
341
|
+
NSMutableArray<UIColor *> *layerColors = [NSMutableArray arrayWithCapacity:colors.size()];
|
|
363
342
|
for (size_t i = 0; i < colors.size(); i++) {
|
|
364
|
-
|
|
343
|
+
UIColor *color = RCTUIColorFromSharedColor(colors[i]);
|
|
344
|
+
[layerColors addObject:color ?: [UIColor blackColor]];
|
|
365
345
|
}
|
|
346
|
+
_layerColors = layerColors;
|
|
366
347
|
[self _rebuildCachedColors];
|
|
367
348
|
needsRedraw = YES;
|
|
368
349
|
}
|
|
369
350
|
|
|
351
|
+
if (oldViewProps.color != newViewProps.color) {
|
|
352
|
+
_tintColor = newViewProps.color ? RCTUIColorFromSharedColor(newViewProps.color) : nil;
|
|
353
|
+
[self _rebuildCachedColors];
|
|
354
|
+
needsRedraw = YES;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (oldViewProps.tintLayers != newViewProps.tintLayers ||
|
|
358
|
+
oldViewProps.codepoints != newViewProps.codepoints) {
|
|
359
|
+
_tintable.assign(newViewProps.codepoints.size(), false);
|
|
360
|
+
for (int layer : newViewProps.tintLayers) {
|
|
361
|
+
if (layer >= 0 && (size_t)layer < _tintable.size()) _tintable[layer] = true;
|
|
362
|
+
}
|
|
363
|
+
needsRedraw = YES;
|
|
364
|
+
}
|
|
365
|
+
|
|
370
366
|
[super updateProps:props oldProps:oldProps];
|
|
371
367
|
if (needsRedraw) [self _setNeedsRedraw];
|
|
372
368
|
}
|
|
@@ -391,6 +387,21 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
|
|
|
391
387
|
}
|
|
392
388
|
}
|
|
393
389
|
|
|
390
|
+
// Trait-dependent colors (DynamicColorIOS, PlatformColor) resolve to a different
|
|
391
|
+
// CGColor when the interface style or contrast changes. Fabric does not re-send
|
|
392
|
+
// props for that, so re-resolve and redraw here.
|
|
393
|
+
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
|
|
394
|
+
[super traitCollectionDidChange:previousTraitCollection];
|
|
395
|
+
|
|
396
|
+
if (_layerColors.count == 0 && !_tintColor) return;
|
|
397
|
+
if (![self.traitCollection hasDifferentColorAppearanceComparedToTraitCollection:previousTraitCollection]) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
[self _rebuildCachedColors];
|
|
402
|
+
[self _setNeedsRedraw];
|
|
403
|
+
}
|
|
404
|
+
|
|
394
405
|
- (void)_resolveFontIfMissing {
|
|
395
406
|
if (_font || _fontFamily.length == 0) return;
|
|
396
407
|
_font = NanoIconResolveFont(_fontFamily, _fontSize);
|
|
@@ -402,7 +413,7 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
|
|
|
402
413
|
}
|
|
403
414
|
|
|
404
415
|
- (void)_setNeedsRedraw {
|
|
405
|
-
if (
|
|
416
|
+
if (_drawingLayer) {
|
|
406
417
|
[_drawingLayer setNeedsDisplay];
|
|
407
418
|
} else {
|
|
408
419
|
[self setNeedsDisplay];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PreparedSvgCache, type SvgWorkerPool } from '../src/core/pipeline/index';
|
|
1
2
|
import type { NanoLogger } from './logger';
|
|
2
3
|
export type IconSetConfig = {
|
|
3
4
|
/** Path to folder of SVG files (relative to project root). */
|
|
@@ -36,4 +37,8 @@ export declare class IconSetBuildError extends Error {
|
|
|
36
37
|
*/
|
|
37
38
|
export declare function buildAllFonts(iconSets: IconSetConfig[], projectRoot: string, options?: {
|
|
38
39
|
logger?: NanoLogger;
|
|
40
|
+
keepOutputsOnFailure?: boolean;
|
|
41
|
+
preparedSvgCache?: PreparedSvgCache;
|
|
42
|
+
svgWorkerPool?: SvgWorkerPool;
|
|
43
|
+
withWeb?: boolean;
|
|
39
44
|
}): Promise<BuiltFont[]>;
|
|
@@ -18,17 +18,24 @@ class IconSetBuildError extends Error {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
exports.IconSetBuildError = IconSetBuildError;
|
|
21
|
-
const DEFAULT_SAFE_ZONE_RATIO =
|
|
21
|
+
const DEFAULT_SAFE_ZONE_RATIO = 1;
|
|
22
22
|
const DEFAULT_UPM = 1024;
|
|
23
23
|
const DEFAULT_START_UNICODE = 0xe900;
|
|
24
|
-
function
|
|
24
|
+
function webOutputFor(configured, withWeb) {
|
|
25
|
+
if (!configured)
|
|
26
|
+
return 'forbidden';
|
|
27
|
+
if (withWeb)
|
|
28
|
+
return 'required';
|
|
29
|
+
return 'ignored';
|
|
30
|
+
}
|
|
31
|
+
function familyOfCurrentOutput(inputHash, outputDir, fontFamily, linking, webOutput, logger) {
|
|
25
32
|
const ttfPath = path_1.default.join(outputDir, `${fontFamily}.ttf`);
|
|
26
33
|
const glyphmapPath = path_1.default.join(outputDir, `${fontFamily}.glyphmap.json`);
|
|
27
34
|
const woff2Path = path_1.default.join(outputDir, `${fontFamily}.woff2`);
|
|
28
35
|
if (!fs_1.default.existsSync(outputDir) ||
|
|
29
36
|
!fs_1.default.existsSync(ttfPath) ||
|
|
30
37
|
!fs_1.default.existsSync(glyphmapPath) ||
|
|
31
|
-
(
|
|
38
|
+
(webOutput === 'required' && !fs_1.default.existsSync(woff2Path))) {
|
|
32
39
|
return undefined;
|
|
33
40
|
}
|
|
34
41
|
const glyphmap = JSON.parse(fs_1.default.readFileSync(glyphmapPath, 'utf8'));
|
|
@@ -36,11 +43,12 @@ function familyOfCurrentOutput(inputHash, outputDir, fontFamily, linking, web, l
|
|
|
36
43
|
const storedFamily = glyphmap?.m?.f;
|
|
37
44
|
const storedLinking = glyphmap?.m?.l === 'd' ? 'dynamic' : 'static';
|
|
38
45
|
const storedWeb = glyphmap?.m?.w === true;
|
|
46
|
+
const webCurrent = webOutput === 'ignored' || storedWeb === (webOutput === 'required');
|
|
39
47
|
if (storedHash &&
|
|
40
48
|
storedFamily &&
|
|
41
49
|
storedHash === inputHash &&
|
|
42
50
|
storedLinking === linking &&
|
|
43
|
-
|
|
51
|
+
webCurrent) {
|
|
44
52
|
const iconCount = Object.keys(glyphmap?.i ?? {}).length;
|
|
45
53
|
logger?.succeed(`${fontFamily}.ttf is up to date [${iconCount} icon${iconCount === 1 ? '' : 's'}]`);
|
|
46
54
|
return storedFamily;
|
|
@@ -53,6 +61,7 @@ function familyOfCurrentOutput(inputHash, outputDir, fontFamily, linking, web, l
|
|
|
53
61
|
* Skips generation for a set if that output folder already contains the expected .ttf and .glyphmap.json.
|
|
54
62
|
*/
|
|
55
63
|
async function buildAllFonts(iconSets, projectRoot, options) {
|
|
64
|
+
const withWeb = options?.withWeb ?? true;
|
|
56
65
|
const logger = options?.logger;
|
|
57
66
|
const version = (0, packageVersion_1.packageVersion)();
|
|
58
67
|
const toolchain = (0, packageVersion_1.fontToolchainVersions)();
|
|
@@ -64,7 +73,8 @@ async function buildAllFonts(iconSets, projectRoot, options) {
|
|
|
64
73
|
const inputDir = path_1.default.resolve(projectRoot, set.inputDir);
|
|
65
74
|
const fontFamily = set.fontFamily ?? path_1.default.basename(inputDir);
|
|
66
75
|
const linking = set.linking ?? 'static';
|
|
67
|
-
const web = set.web ?? false;
|
|
76
|
+
const web = (set.web ?? false) && withWeb;
|
|
77
|
+
const webOutput = webOutputFor(set.web ?? false, withWeb);
|
|
68
78
|
if (!fs_1.default.existsSync(inputDir)) {
|
|
69
79
|
throw new Error(`[react-native-nano-icons] Input directory does not exist: ${inputDir} (from "${set.inputDir}")`);
|
|
70
80
|
}
|
|
@@ -91,14 +101,14 @@ async function buildAllFonts(iconSets, projectRoot, options) {
|
|
|
91
101
|
linking,
|
|
92
102
|
web,
|
|
93
103
|
};
|
|
94
|
-
const inputHash = (0, fingerPrint_1.
|
|
104
|
+
const { hash: inputHash, svgHashByFile } = (0, fingerPrint_1.fingerprintSvgDirSync)(inputDir, {
|
|
95
105
|
upm: config.upm,
|
|
96
106
|
safeZone: config.safeZone,
|
|
97
107
|
startUnicode: config.startUnicode,
|
|
98
108
|
version,
|
|
99
109
|
toolchain,
|
|
100
110
|
});
|
|
101
|
-
const currentFamily = familyOfCurrentOutput(inputHash, outputDir, fontFamily, linking,
|
|
111
|
+
const currentFamily = familyOfCurrentOutput(inputHash, outputDir, fontFamily, linking, webOutput, logger);
|
|
102
112
|
if (currentFamily) {
|
|
103
113
|
results.push({
|
|
104
114
|
fontFamily,
|
|
@@ -113,23 +123,35 @@ async function buildAllFonts(iconSets, projectRoot, options) {
|
|
|
113
123
|
allSkipped = false;
|
|
114
124
|
const tempDir = path_1.default.join(projectRoot, '.temp_layers', fontFamily);
|
|
115
125
|
logger?.start(`Building ${fontFamily} (${i + 1}/${iconSets.length})…`);
|
|
116
|
-
if (
|
|
126
|
+
if (webOutput === 'forbidden' && fs_1.default.existsSync(woff2Path)) {
|
|
117
127
|
fs_1.default.unlinkSync(woff2Path);
|
|
128
|
+
}
|
|
118
129
|
let out;
|
|
119
130
|
try {
|
|
120
|
-
out = await (0, index_1.runFontPipeline)(config, { inputDir, outputDir, tempDir }, {
|
|
131
|
+
out = await (0, index_1.runFontPipeline)(config, { inputDir, outputDir, tempDir }, {
|
|
132
|
+
logger,
|
|
133
|
+
inputHash,
|
|
134
|
+
preparedSvgCache: options?.preparedSvgCache,
|
|
135
|
+
svgWorkerPool: options?.svgWorkerPool,
|
|
136
|
+
svgHashByFile,
|
|
137
|
+
});
|
|
121
138
|
}
|
|
122
139
|
catch (err) {
|
|
123
|
-
if (
|
|
124
|
-
fs_1.default.
|
|
125
|
-
|
|
126
|
-
fs_1.default.
|
|
127
|
-
|
|
128
|
-
fs_1.default.
|
|
140
|
+
if (!options?.keepOutputsOnFailure) {
|
|
141
|
+
if (fs_1.default.existsSync(ttfPath))
|
|
142
|
+
fs_1.default.unlinkSync(ttfPath);
|
|
143
|
+
if (fs_1.default.existsSync(glyphmapPath))
|
|
144
|
+
fs_1.default.unlinkSync(glyphmapPath);
|
|
145
|
+
if (fs_1.default.existsSync(woff2Path))
|
|
146
|
+
fs_1.default.unlinkSync(woff2Path);
|
|
147
|
+
}
|
|
129
148
|
logger?.fail(err instanceof Error ? err.message : String(err));
|
|
130
149
|
failures.push(fontFamily);
|
|
131
150
|
continue;
|
|
132
151
|
}
|
|
152
|
+
if (webOutput === 'ignored' && fs_1.default.existsSync(woff2Path)) {
|
|
153
|
+
fs_1.default.unlinkSync(woff2Path);
|
|
154
|
+
}
|
|
133
155
|
results.push({
|
|
134
156
|
fontFamily,
|
|
135
157
|
family: out.family,
|