@ng-native/desktop 0.24.0 → 0.26.0
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/bin/package.mjs +65 -9
- package/bin/prebuilt.mjs +25 -4
- package/native/CMakeLists.txt +51 -4
- package/native/appkit/CMakeLists.txt +16 -2
- package/native/appkit/appkit-backend.mm +28 -3
- package/native/appkit/cg-canvas.h +5 -0
- package/native/appkit/cg-canvas.mm +21 -6
- package/native/appkit/desktop-expo.h +6 -0
- package/native/appkit/desktop-expo.mm +5 -0
- package/native/appkit/host-view.mm +32 -0
- package/native/appkit/image-request.h +2 -10
- package/native/appkit/image-request.mm +0 -22
- package/native/appkit/image-view.mm +121 -4
- package/native/appkit/main.mm +130 -185
- package/native/appkit/scroll-view.mm +57 -16
- package/native/appkit/scrollers.h +22 -2
- package/native/appkit/scrollers.mm +221 -2
- package/native/appkit/split-view.h +4 -0
- package/native/appkit/split-view.mm +60 -12
- package/native/appkit/system-access.mm +3 -0
- package/native/appkit/system.mm +33 -48
- package/native/appkit/text-layout.h +6 -0
- package/native/appkit/text-layout.mm +147 -24
- package/native/appkit/view-effects.h +27 -0
- package/native/appkit/view-effects.mm +90 -0
- package/native/cmake/react-native.cmake +9 -0
- package/native/cmake/runtime-dependencies.cmake +32 -1
- package/native/core/include/ngn/app-info.h +3 -2
- package/native/core/include/ngn/app-menus.h +5 -11
- package/native/core/include/ngn/default-menu.h +16 -6
- package/native/core/include/ngn/desktop-expo.h +0 -5
- package/native/core/include/ngn/desktop-modules.h +144 -0
- package/native/core/include/ngn/dev-server.h +12 -3
- package/native/core/include/ngn/host-os.h +45 -0
- package/native/core/include/ngn/host-views.h +25 -0
- package/native/core/include/ngn/image-source.h +18 -0
- package/native/core/include/ngn/launch-settings.h +9 -7
- package/native/core/include/ngn/module-registry.h +2 -0
- package/native/core/include/ngn/notifications.h +6 -0
- package/native/core/include/ngn/runtime.h +4 -1
- package/native/core/include/ngn/scrollers.h +5 -0
- package/native/core/include/ngn/spawn-rules.h +3 -2
- package/native/core/include/ngn/split-view.h +12 -0
- package/native/core/include/ngn/system.h +47 -0
- package/native/core/include/ngn/text-measurer.h +11 -0
- package/native/core/include/ngn/undo.h +27 -0
- package/native/core/include/ngn/updates.h +3 -2
- package/native/core/include/ngn/view-filter.h +33 -0
- package/native/core/src/app-menus.cpp +9 -11
- package/native/core/src/default-menu.cpp +6 -2
- package/native/core/src/dev-server-helper.cpp +3 -2
- package/native/core/src/dev-server.cpp +22 -5
- package/native/core/src/host-os.cpp +20 -0
- package/native/core/src/host-views.cpp +25 -0
- package/native/core/src/image-source.cpp +30 -0
- package/native/core/src/launch-settings.cpp +10 -6
- package/native/core/src/module-registry.cpp +9 -0
- package/native/core/src/modules/app-info.cpp +4 -4
- package/native/core/src/modules/app-modules.cpp +4 -2
- package/native/core/src/modules/desktop-expo.cpp +0 -5
- package/native/core/src/modules/desktop-modules.cpp +132 -0
- package/native/core/src/modules/notifications.cpp +4 -4
- package/native/core/src/runtime.cpp +2 -0
- package/native/core/src/scrollers.cpp +11 -0
- package/native/core/src/spawn-rules.cpp +1 -4
- package/native/core/src/split-view.cpp +10 -0
- package/native/core/src/system.cpp +52 -0
- package/native/core/src/text-layout-manager.cpp +13 -0
- package/native/core/src/undo-stacks.cpp +71 -0
- package/native/core/src/view-filter.cpp +114 -0
- package/native/scripts/build-hermes.sh +19 -7
- package/native/scripts/build-icu.sh +36 -0
- package/native/scripts/build-lock.sh +21 -0
- package/native/scripts/build.sh +46 -7
- package/native/scripts/fetch-hermes.sh +70 -0
- package/native/scripts/fetch.sh +24 -2
- package/native/scripts/hermes-built.sh +5 -4
- package/native/scripts/hermes-target.sh +18 -0
- package/native/scripts/icu-filter.json +22 -0
- package/native/scripts/make-prebuilt.mjs +13 -6
- package/native/scripts/prebuilt-host-cache.mjs +1 -1
- package/native/shim/openssl/sha.h +108 -3
- package/native/shim/text-platform/react/renderer/textlayoutmanager/TextLayoutManager.h +52 -0
- package/package.json +2 -2
- package/prebuilt.json +6 -6
|
@@ -17,6 +17,8 @@ struct TextLine {
|
|
|
17
17
|
CGPoint origin; // baseline origin, y measured from the top of the text box
|
|
18
18
|
CGFloat width;
|
|
19
19
|
bool rightToLeft{false}; // its paragraph runs right to left, so a justified last line is on the right
|
|
20
|
+
CGFloat top{0}; // the top of its line box, from the top of the text box
|
|
21
|
+
CGFloat height{0}; // its line box's height
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
struct TextLayout {
|
|
@@ -53,6 +55,10 @@ class CoreTextMeasurer final : public TextMeasurer {
|
|
|
53
55
|
const facebook::react::AttributedString &text,
|
|
54
56
|
const facebook::react::ParagraphAttributes ¶graph,
|
|
55
57
|
facebook::react::Float maxWidth) const override;
|
|
58
|
+
facebook::react::LinesMeasurements lines(
|
|
59
|
+
const facebook::react::AttributedString &text,
|
|
60
|
+
const facebook::react::ParagraphAttributes ¶graph,
|
|
61
|
+
facebook::react::Float width) const override;
|
|
56
62
|
};
|
|
57
63
|
|
|
58
64
|
} // namespace ngn
|
|
@@ -276,6 +276,9 @@ void useFontLibrary(std::shared_ptr<const FontLibrary> library) {
|
|
|
276
276
|
gFontLibrary = std::move(library);
|
|
277
277
|
}
|
|
278
278
|
|
|
279
|
+
// A line through a range of text, in kCTUnderlineStyle's numbers, which Core Text does not draw.
|
|
280
|
+
static const CFStringRef kStrikethroughStyle = CFSTR("NGNStrikethroughStyle");
|
|
281
|
+
|
|
279
282
|
CFAttributedStringRef makeAttributedString(const AttributedString &attributedString) {
|
|
280
283
|
CFMutableAttributedStringRef out = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0);
|
|
281
284
|
CFAttributedStringBeginEditing(out);
|
|
@@ -336,12 +339,35 @@ CFAttributedStringRef makeAttributedString(const AttributedString &attributedStr
|
|
|
336
339
|
CFAttributedStringSetAttribute(out, range, kCTParagraphStyleAttributeName, style);
|
|
337
340
|
CFRelease(style);
|
|
338
341
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
342
|
+
// Core Text draws an underline, in its style and colour; a line through is drawText's.
|
|
343
|
+
auto line = a.textDecorationLineType.value_or(TextDecorationLineType::None);
|
|
344
|
+
bool under = line == TextDecorationLineType::Underline || line == TextDecorationLineType::UnderlineStrikethrough;
|
|
345
|
+
bool through = line == TextDecorationLineType::Strikethrough || line == TextDecorationLineType::UnderlineStrikethrough;
|
|
346
|
+
if (under || through) {
|
|
347
|
+
auto decoration = a.textDecorationStyle.value_or(TextDecorationStyle::Solid);
|
|
348
|
+
int32_t style = decoration == TextDecorationStyle::Double ? kCTUnderlineStyleDouble : kCTUnderlineStyleSingle;
|
|
349
|
+
if (decoration == TextDecorationStyle::Dotted) {
|
|
350
|
+
style |= kCTUnderlinePatternDot;
|
|
351
|
+
} else if (decoration == TextDecorationStyle::Dashed) {
|
|
352
|
+
style |= kCTUnderlinePatternDash;
|
|
353
|
+
}
|
|
354
|
+
CFNumberRef n = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &style);
|
|
355
|
+
CFAttributedStringSetAttribute(out, range, under ? kCTUnderlineStyleAttributeName : kStrikethroughStyle, n);
|
|
356
|
+
if (under && through) {
|
|
357
|
+
CFAttributedStringSetAttribute(out, range, kStrikethroughStyle, n);
|
|
358
|
+
}
|
|
344
359
|
CFRelease(n);
|
|
360
|
+
if (a.textDecorationColor) {
|
|
361
|
+
// Faded with the text, as its foreground is.
|
|
362
|
+
CGColorRef decorationColor = cgColor(a.textDecorationColor);
|
|
363
|
+
if (!std::isnan(a.opacity)) {
|
|
364
|
+
CGColorRef faded = CGColorCreateCopyWithAlpha(decorationColor, CGColorGetAlpha(decorationColor) * a.opacity);
|
|
365
|
+
CGColorRelease(decorationColor);
|
|
366
|
+
decorationColor = faded;
|
|
367
|
+
}
|
|
368
|
+
CFAttributedStringSetAttribute(out, range, kCTUnderlineColorAttributeName, decorationColor);
|
|
369
|
+
CGColorRelease(decorationColor);
|
|
370
|
+
}
|
|
345
371
|
}
|
|
346
372
|
CFRelease(font);
|
|
347
373
|
}
|
|
@@ -429,7 +455,7 @@ TextLayout layoutText(
|
|
|
429
455
|
if (fixed <= 0) {
|
|
430
456
|
baseline = y + ascent;
|
|
431
457
|
}
|
|
432
|
-
layout.lines.push_back({line, CGPointMake(0, baseline), width, rightToLeftAt(layout.string, r.location, paragraph)});
|
|
458
|
+
layout.lines.push_back({line, CGPointMake(0, baseline), width, rightToLeftAt(layout.string, r.location, paragraph), y, height});
|
|
433
459
|
widest = std::max(widest, width);
|
|
434
460
|
y += height;
|
|
435
461
|
at += count;
|
|
@@ -442,32 +468,91 @@ TextLayout layoutText(
|
|
|
442
468
|
return layout;
|
|
443
469
|
}
|
|
444
470
|
|
|
471
|
+
// Each run's line through, half its font's x-height above the baseline at `baseline`, the
|
|
472
|
+
// underline's thickness and in the underline's colour, or the text's: a double one is two lines,
|
|
473
|
+
// and a dotted or dashed one is stroked in that pattern.
|
|
474
|
+
static void drawStrikethroughs(CTLineRef line, CGContextRef context, CGPoint baseline) {
|
|
475
|
+
CFArrayRef runs = CTLineGetGlyphRuns(line);
|
|
476
|
+
for (CFIndex i = 0; i < CFArrayGetCount(runs); i++) {
|
|
477
|
+
auto run = (CTRunRef)CFArrayGetValueAtIndex(runs, i);
|
|
478
|
+
CFDictionaryRef attributes = CTRunGetAttributes(run);
|
|
479
|
+
auto styleNumber = (CFNumberRef)CFDictionaryGetValue(attributes, kStrikethroughStyle);
|
|
480
|
+
auto font = (CTFontRef)CFDictionaryGetValue(attributes, kCTFontAttributeName);
|
|
481
|
+
if (styleNumber == nullptr || font == nullptr) {
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
int32_t style = 0;
|
|
485
|
+
CFNumberGetValue(styleNumber, kCFNumberSInt32Type, &style);
|
|
486
|
+
auto color = (CGColorRef)CFDictionaryGetValue(attributes, kCTUnderlineColorAttributeName);
|
|
487
|
+
if (color == nullptr) {
|
|
488
|
+
color = (CGColorRef)CFDictionaryGetValue(attributes, kCTForegroundColorAttributeName);
|
|
489
|
+
}
|
|
490
|
+
// The run as drawn: its first glyph's position on the line and its advance, whatever direction
|
|
491
|
+
// the run or the line goes.
|
|
492
|
+
if (CTRunGetGlyphCount(run) == 0) {
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
CGPoint first = CGPointZero;
|
|
496
|
+
CTRunGetPositions(run, CFRangeMake(0, 1), &first);
|
|
497
|
+
CGFloat left = first.x;
|
|
498
|
+
CGFloat width = CTRunGetTypographicBounds(run, CFRangeMake(0, 0), nullptr, nullptr, nullptr);
|
|
499
|
+
CGFloat thickness = std::max<CGFloat>(CTFontGetUnderlineThickness(font), 1);
|
|
500
|
+
CGFloat middle = baseline.y - CTFontGetXHeight(font) / 2;
|
|
501
|
+
bool twice = (style & 0xff) == kCTUnderlineStyleDouble;
|
|
502
|
+
CGContextSaveGState(context);
|
|
503
|
+
if (color != nullptr) {
|
|
504
|
+
CGContextSetStrokeColorWithColor(context, color);
|
|
505
|
+
}
|
|
506
|
+
CGContextSetLineWidth(context, thickness);
|
|
507
|
+
if (style & kCTUnderlinePatternDot) {
|
|
508
|
+
CGFloat dots[] = {thickness, thickness * 2};
|
|
509
|
+
CGContextSetLineDash(context, 0, dots, 2);
|
|
510
|
+
} else if (style & kCTUnderlinePatternDash) {
|
|
511
|
+
CGFloat dashes[] = {thickness * 4, thickness * 2};
|
|
512
|
+
CGContextSetLineDash(context, 0, dashes, 2);
|
|
513
|
+
}
|
|
514
|
+
for (CGFloat y : twice ? std::vector<CGFloat>{middle - thickness, middle + thickness} : std::vector<CGFloat>{middle}) {
|
|
515
|
+
CGContextMoveToPoint(context, baseline.x + left, y);
|
|
516
|
+
CGContextAddLineToPoint(context, baseline.x + left + width, y);
|
|
517
|
+
}
|
|
518
|
+
CGContextStrokePath(context);
|
|
519
|
+
CGContextRestoreGState(context);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// How far right of the box's left edge a line starts: its paragraph's alignment in a box this wide.
|
|
524
|
+
static CGFloat lineOffset(const TextLayout &layout, const TextLine &l, CGFloat boxWidth) {
|
|
525
|
+
CFRange r = CTLineGetStringRange(l.line);
|
|
526
|
+
CTTextAlignment alignment = kCTTextAlignmentNatural;
|
|
527
|
+
CTParagraphStyleRef style = r.length > 0
|
|
528
|
+
? (CTParagraphStyleRef)CFAttributedStringGetAttribute(
|
|
529
|
+
layout.string, r.location, kCTParagraphStyleAttributeName, nullptr)
|
|
530
|
+
: nullptr;
|
|
531
|
+
if (style != nullptr) {
|
|
532
|
+
CTParagraphStyleGetValueForSpecifier(style, kCTParagraphStyleSpecifierAlignment, sizeof(alignment), &alignment);
|
|
533
|
+
}
|
|
534
|
+
CGFloat x = 0;
|
|
535
|
+
if (alignment == kCTTextAlignmentCenter) {
|
|
536
|
+
x = (boxWidth - l.width) / 2;
|
|
537
|
+
} else if (alignment == kCTTextAlignmentRight) {
|
|
538
|
+
x = boxWidth - l.width;
|
|
539
|
+
} else if (alignment == kCTTextAlignmentJustified && l.rightToLeft) {
|
|
540
|
+
// A justified paragraph's last line follows the paragraph's direction.
|
|
541
|
+
x = boxWidth - l.width;
|
|
542
|
+
}
|
|
543
|
+
return x;
|
|
544
|
+
}
|
|
545
|
+
|
|
445
546
|
void drawText(const TextLayout &layout, CGContextRef context, CGPoint origin, CGFloat boxWidth) {
|
|
446
547
|
CGContextSaveGState(context);
|
|
447
548
|
// The view is flipped; glyphs are drawn with an inverted text matrix rather than by flipping
|
|
448
549
|
// the whole context, so line origins stay top-down.
|
|
449
550
|
CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1, -1));
|
|
450
551
|
for (const auto &l : layout.lines) {
|
|
451
|
-
|
|
452
|
-
CTTextAlignment alignment = kCTTextAlignmentNatural;
|
|
453
|
-
CTParagraphStyleRef style = r.length > 0
|
|
454
|
-
? (CTParagraphStyleRef)CFAttributedStringGetAttribute(
|
|
455
|
-
layout.string, r.location, kCTParagraphStyleAttributeName, nullptr)
|
|
456
|
-
: nullptr;
|
|
457
|
-
if (style != nullptr) {
|
|
458
|
-
CTParagraphStyleGetValueForSpecifier(style, kCTParagraphStyleSpecifierAlignment, sizeof(alignment), &alignment);
|
|
459
|
-
}
|
|
460
|
-
CGFloat x = 0;
|
|
461
|
-
if (alignment == kCTTextAlignmentCenter) {
|
|
462
|
-
x = (boxWidth - l.width) / 2;
|
|
463
|
-
} else if (alignment == kCTTextAlignmentRight) {
|
|
464
|
-
x = boxWidth - l.width;
|
|
465
|
-
} else if (alignment == kCTTextAlignmentJustified && l.rightToLeft) {
|
|
466
|
-
// A justified paragraph's last line follows the paragraph's direction.
|
|
467
|
-
x = boxWidth - l.width;
|
|
468
|
-
}
|
|
552
|
+
CGFloat x = lineOffset(layout, l, boxWidth);
|
|
469
553
|
CGContextSetTextPosition(context, origin.x + x, origin.y + l.origin.y);
|
|
470
554
|
CTLineDraw(l.line, context);
|
|
555
|
+
drawStrikethroughs(l.line, context, CGPointMake(origin.x + x, origin.y + l.origin.y));
|
|
471
556
|
}
|
|
472
557
|
CGContextRestoreGState(context);
|
|
473
558
|
}
|
|
@@ -482,4 +567,42 @@ facebook::react::Size CoreTextMeasurer::measure(
|
|
|
482
567
|
}
|
|
483
568
|
}
|
|
484
569
|
|
|
570
|
+
LinesMeasurements CoreTextMeasurer::lines(
|
|
571
|
+
const AttributedString &text,
|
|
572
|
+
const ParagraphAttributes ¶graph,
|
|
573
|
+
facebook::react::Float width) const {
|
|
574
|
+
@autoreleasepool {
|
|
575
|
+
// The slack drawing gives the width Yoga rounded (NGNView's drawRect:), so the lines match.
|
|
576
|
+
auto layout = layoutText(text, paragraph, width + 0.5);
|
|
577
|
+
CFStringRef string = layout.string ? CFAttributedStringGetString(layout.string) : nullptr;
|
|
578
|
+
LinesMeasurements lines;
|
|
579
|
+
for (const auto &l : layout.lines) {
|
|
580
|
+
CGFloat ascent = 0, descent = 0, leading = 0;
|
|
581
|
+
CTLineGetTypographicBounds(l.line, &ascent, &descent, &leading);
|
|
582
|
+
CFRange range = CTLineGetStringRange(l.line);
|
|
583
|
+
NSString *lineText = string ? (__bridge NSString *)string : @"";
|
|
584
|
+
lineText = [lineText substringWithRange:NSMakeRange(range.location, range.length)];
|
|
585
|
+
CGFloat capHeight = 0, xHeight = 0;
|
|
586
|
+
CFArrayRef runs = CTLineGetGlyphRuns(l.line);
|
|
587
|
+
if (CFArrayGetCount(runs) > 0) {
|
|
588
|
+
auto font = (CTFontRef)CFDictionaryGetValue(
|
|
589
|
+
CTRunGetAttributes((CTRunRef)CFArrayGetValueAtIndex(runs, 0)), kCTFontAttributeName);
|
|
590
|
+
if (font != nullptr) {
|
|
591
|
+
capHeight = CTFontGetCapHeight(font);
|
|
592
|
+
xHeight = CTFontGetXHeight(font);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
lines.emplace_back(
|
|
596
|
+
std::string(lineText.UTF8String),
|
|
597
|
+
facebook::react::Rect{{static_cast<Float>(lineOffset(layout, l, width)), static_cast<Float>(l.top)}, {static_cast<Float>(l.width), static_cast<Float>(l.height)}},
|
|
598
|
+
static_cast<Float>(descent),
|
|
599
|
+
static_cast<Float>(capHeight),
|
|
600
|
+
static_cast<Float>(l.origin.y - l.top),
|
|
601
|
+
static_cast<Float>(xHeight));
|
|
602
|
+
}
|
|
603
|
+
return lines;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
|
|
485
607
|
} // namespace ngn
|
|
608
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// What a view's `filter` and `mix-blend-mode` become on its layer: Core Image filters and a
|
|
2
|
+
// compositing filter, which Core Animation applies to the layer and its sublayers.
|
|
3
|
+
#pragma once
|
|
4
|
+
|
|
5
|
+
#import <CoreImage/CoreImage.h>
|
|
6
|
+
#import <Foundation/Foundation.h>
|
|
7
|
+
|
|
8
|
+
#include "ngn/view-filter.h"
|
|
9
|
+
|
|
10
|
+
#include <react/renderer/graphics/BlendMode.h>
|
|
11
|
+
|
|
12
|
+
#include <vector>
|
|
13
|
+
|
|
14
|
+
namespace ngn::appkit {
|
|
15
|
+
|
|
16
|
+
// The layer's `filters` for the steps, in their order. Core Animation runs a layer's filters in a
|
|
17
|
+
// linear working space, where a colour matrix of the Filter Effects spec (written for sRGB values)
|
|
18
|
+
// would mix the channels wrongly, so the steps sit between the conversions to sRGB and back, and a
|
|
19
|
+
// colour step is clamped as the spec does. A drop shadow draws nothing: a layer filter cannot add
|
|
20
|
+
// a copy of the view under it. Nil when no step draws anything.
|
|
21
|
+
NSArray<CIFilter *> *layerFilters(const std::vector<FilterStep> &steps);
|
|
22
|
+
|
|
23
|
+
// The layer's `compositingFilter` for `mix-blend-mode`, which blends the view with what is drawn
|
|
24
|
+
// under it as React Native iOS does (RCTViewComponentView); nil for `normal`.
|
|
25
|
+
NSString *blendFilterName(facebook::react::BlendMode mode);
|
|
26
|
+
|
|
27
|
+
} // namespace ngn::appkit
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#import "view-effects.h"
|
|
2
|
+
|
|
3
|
+
namespace ngn::appkit {
|
|
4
|
+
|
|
5
|
+
namespace {
|
|
6
|
+
|
|
7
|
+
CIFilter *colorMatrix(const std::array<double, 20> &m) {
|
|
8
|
+
CIFilter *filter = [CIFilter filterWithName:@"CIColorMatrix"];
|
|
9
|
+
// Row by row of the spec's 4 by 5 matrix: each output channel's weights, and the offsets as the bias.
|
|
10
|
+
[filter setValue:[CIVector vectorWithX:m[0] Y:m[1] Z:m[2] W:m[3]] forKey:@"inputRVector"];
|
|
11
|
+
[filter setValue:[CIVector vectorWithX:m[5] Y:m[6] Z:m[7] W:m[8]] forKey:@"inputGVector"];
|
|
12
|
+
[filter setValue:[CIVector vectorWithX:m[10] Y:m[11] Z:m[12] W:m[13]] forKey:@"inputBVector"];
|
|
13
|
+
[filter setValue:[CIVector vectorWithX:m[15] Y:m[16] Z:m[17] W:m[18]] forKey:@"inputAVector"];
|
|
14
|
+
[filter setValue:[CIVector vectorWithX:m[4] Y:m[9] Z:m[14] W:m[19]] forKey:@"inputBiasVector"];
|
|
15
|
+
return filter;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
} // namespace
|
|
19
|
+
|
|
20
|
+
NSArray<CIFilter *> *layerFilters(const std::vector<FilterStep> &steps) {
|
|
21
|
+
NSMutableArray<CIFilter *> *filters = [NSMutableArray array];
|
|
22
|
+
for (const auto &step : steps) {
|
|
23
|
+
switch (step.type) {
|
|
24
|
+
case FilterStep::Type::ColorMatrix:
|
|
25
|
+
[filters addObject:colorMatrix(step.matrix)];
|
|
26
|
+
[filters addObject:[CIFilter filterWithName:@"CIColorClamp"]];
|
|
27
|
+
break;
|
|
28
|
+
case FilterStep::Type::Blur: {
|
|
29
|
+
CIFilter *blur = [CIFilter filterWithName:@"CIGaussianBlur"];
|
|
30
|
+
// Core Image's radius is the Gaussian's standard deviation, as CSS's blur() is.
|
|
31
|
+
[blur setValue:@(step.standardDeviation) forKey:kCIInputRadiusKey];
|
|
32
|
+
[filters addObject:blur];
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
case FilterStep::Type::DropShadow:
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (filters.count == 0) {
|
|
40
|
+
return nil;
|
|
41
|
+
}
|
|
42
|
+
// The steps run on sRGB values, as Chrome's do, between the conversions out of and back into the
|
|
43
|
+
// working space.
|
|
44
|
+
[filters insertObject:[CIFilter filterWithName:@"CILinearToSRGBToneCurve"] atIndex:0];
|
|
45
|
+
[filters addObject:[CIFilter filterWithName:@"CISRGBToneCurveToLinear"]];
|
|
46
|
+
return filters;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
NSString *blendFilterName(facebook::react::BlendMode mode) {
|
|
50
|
+
using facebook::react::BlendMode;
|
|
51
|
+
switch (mode) {
|
|
52
|
+
case BlendMode::Multiply:
|
|
53
|
+
return @"multiplyBlendMode";
|
|
54
|
+
case BlendMode::Screen:
|
|
55
|
+
return @"screenBlendMode";
|
|
56
|
+
case BlendMode::Overlay:
|
|
57
|
+
return @"overlayBlendMode";
|
|
58
|
+
case BlendMode::Darken:
|
|
59
|
+
return @"darkenBlendMode";
|
|
60
|
+
case BlendMode::Lighten:
|
|
61
|
+
return @"lightenBlendMode";
|
|
62
|
+
case BlendMode::ColorDodge:
|
|
63
|
+
return @"colorDodgeBlendMode";
|
|
64
|
+
case BlendMode::ColorBurn:
|
|
65
|
+
return @"colorBurnBlendMode";
|
|
66
|
+
case BlendMode::HardLight:
|
|
67
|
+
return @"hardLightBlendMode";
|
|
68
|
+
case BlendMode::SoftLight:
|
|
69
|
+
return @"softLightBlendMode";
|
|
70
|
+
case BlendMode::Difference:
|
|
71
|
+
return @"differenceBlendMode";
|
|
72
|
+
case BlendMode::Exclusion:
|
|
73
|
+
return @"exclusionBlendMode";
|
|
74
|
+
case BlendMode::Hue:
|
|
75
|
+
return @"hueBlendMode";
|
|
76
|
+
case BlendMode::Saturation:
|
|
77
|
+
return @"saturationBlendMode";
|
|
78
|
+
case BlendMode::Color:
|
|
79
|
+
return @"colorBlendMode";
|
|
80
|
+
case BlendMode::Luminosity:
|
|
81
|
+
return @"luminosityBlendMode";
|
|
82
|
+
case BlendMode::PlusLighter:
|
|
83
|
+
return @"linearDodgeBlendMode";
|
|
84
|
+
case BlendMode::Normal:
|
|
85
|
+
return nil;
|
|
86
|
+
}
|
|
87
|
+
return nil;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
} // namespace ngn::appkit
|
|
@@ -19,6 +19,7 @@ include(${REACT_COMMON_DIR}/cmake-utils/internal/react-native-platform-selector.
|
|
|
19
19
|
# read the core's desktop props.
|
|
20
20
|
include_directories(BEFORE SYSTEM
|
|
21
21
|
${CMAKE_CURRENT_LIST_DIR}/../shim/view-platform
|
|
22
|
+
${CMAKE_CURRENT_LIST_DIR}/../shim/text-platform
|
|
22
23
|
${CMAKE_CURRENT_LIST_DIR}/../core/include)
|
|
23
24
|
include_directories(SYSTEM
|
|
24
25
|
${REACT_COMMON_DIR}/react/renderer/graphics/platform/cxx
|
|
@@ -73,6 +74,14 @@ add_library(yoga ALIAS yogacore)
|
|
|
73
74
|
get_target_property(_tlm react_renderer_textlayoutmanager SOURCES)
|
|
74
75
|
list(FILTER _tlm EXCLUDE REGEX "platform/cxx/react/renderer/textlayoutmanager/TextLayoutManager.cpp$")
|
|
75
76
|
set_target_properties(react_renderer_textlayoutmanager PROPERTIES SOURCES "${_tlm}")
|
|
77
|
+
# Its header is the shim's (shim/text-platform), which declares measureLines, in front of the cxx
|
|
78
|
+
# platform's for the target and each one that links it (ParagraphShadowNode's). A directory of its
|
|
79
|
+
# own changes their compile commands, so a build or a compiler cache from before it compiles again.
|
|
80
|
+
foreach(_property INCLUDE_DIRECTORIES INTERFACE_INCLUDE_DIRECTORIES)
|
|
81
|
+
get_target_property(_dirs react_renderer_textlayoutmanager ${_property})
|
|
82
|
+
set_target_properties(react_renderer_textlayoutmanager PROPERTIES
|
|
83
|
+
${_property} "${CMAKE_CURRENT_LIST_DIR}/../shim/text-platform;${_dirs}")
|
|
84
|
+
endforeach()
|
|
76
85
|
|
|
77
86
|
# React Native's component codegen (FBReactNativeSpec), generated by scripts/fetch.sh.
|
|
78
87
|
set(CODEGEN_DIR ${NGN_SOURCES}/codegen)
|
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
# What the runtime half needs beyond the renderer: Hermes, built statically by
|
|
2
|
-
# scripts/build-hermes.sh,
|
|
2
|
+
# scripts/build-hermes.sh, with off macOS the static ICU it was built against, and the one OpenSSL
|
|
3
|
+
# call React Native's dev-server helper makes.
|
|
3
4
|
|
|
5
|
+
if(IS_DIRECTORY "${NGN_HERMES_PREBUILT}")
|
|
6
|
+
# React Native's prebuilt Hermes on macOS: a dynamic framework, which the binary finds beside
|
|
7
|
+
# itself in a build and in Contents/Frameworks in a packaged app.
|
|
8
|
+
set(NGN_HERMES_FRAMEWORK ${NGN_HERMES_PREBUILT}/Library/Frameworks/macosx/hermesvm.framework)
|
|
9
|
+
set(NGN_HERMESC ${NGN_HERMES_PREBUILT}/bin/hermesc)
|
|
10
|
+
foreach(alias hermesvm libhermes)
|
|
11
|
+
add_library(hermes-engine::${alias} INTERFACE IMPORTED GLOBAL)
|
|
12
|
+
set_target_properties(hermes-engine::${alias} PROPERTIES
|
|
13
|
+
INTERFACE_LINK_LIBRARIES ${NGN_HERMES_FRAMEWORK}
|
|
14
|
+
INTERFACE_LINK_OPTIONS "LINKER:-rpath,@executable_path;LINKER:-rpath,@executable_path/../Frameworks")
|
|
15
|
+
endforeach()
|
|
16
|
+
include_directories(SYSTEM ${NGN_HERMES_PREBUILT}/include)
|
|
17
|
+
# Without the cache folder's absolute path, which CMake would add for the framework: the binary
|
|
18
|
+
# finds Hermes only beside itself or in its app's Frameworks, wherever it was built.
|
|
19
|
+
set(CMAKE_SKIP_BUILD_RPATH ON)
|
|
20
|
+
# The tests, which never ship, find it where it was fetched, whichever target built first.
|
|
21
|
+
get_filename_component(_hermes_frameworks ${NGN_HERMES_FRAMEWORK} DIRECTORY)
|
|
22
|
+
set(NGN_HERMES_TEST_RPATH "LINKER:-rpath,${_hermes_frameworks}")
|
|
23
|
+
else()
|
|
4
24
|
if(NOT IS_DIRECTORY "${NGN_HERMES_BUILD}")
|
|
5
25
|
message(FATAL_ERROR "NGN_HERMES_BUILD is not set to a directory; build through scripts/build.sh")
|
|
6
26
|
endif()
|
|
27
|
+
set(NGN_HERMESC ${NGN_HERMES_BUILD}/bin/hermesc)
|
|
7
28
|
|
|
8
29
|
# --- Hermes, static ------------------------------------------------------------------------------
|
|
9
30
|
# React Native's CMakeLists link hermes-engine::hermesvm (0.87 and later) or ::libhermes (before).
|
|
@@ -17,6 +38,15 @@ list(APPEND _hermes_link ${_hermes_context})
|
|
|
17
38
|
if(APPLE)
|
|
18
39
|
# Intl is built over Foundation, as in React Native's Apple builds.
|
|
19
40
|
list(APPEND _hermes_link "-framework Foundation")
|
|
41
|
+
else()
|
|
42
|
+
# Its Unicode layer over the ICU scripts/build-icu.sh built beside it, data and all.
|
|
43
|
+
foreach(lib icui18n icuuc icudata)
|
|
44
|
+
if(NOT EXISTS ${NGN_HERMES_BUILD}/icu/lib/lib${lib}.a)
|
|
45
|
+
message(FATAL_ERROR "${NGN_HERMES_BUILD} has no ICU (icu/lib/lib${lib}.a); build through scripts/build.sh")
|
|
46
|
+
endif()
|
|
47
|
+
list(APPEND _hermes_link ${NGN_HERMES_BUILD}/icu/lib/lib${lib}.a)
|
|
48
|
+
endforeach()
|
|
49
|
+
list(APPEND _hermes_link ${CMAKE_DL_LIBS} pthread)
|
|
20
50
|
endif()
|
|
21
51
|
foreach(alias hermesvm libhermes)
|
|
22
52
|
add_library(hermes-engine::${alias} INTERFACE IMPORTED GLOBAL)
|
|
@@ -24,6 +54,7 @@ foreach(alias hermesvm libhermes)
|
|
|
24
54
|
endforeach()
|
|
25
55
|
# React Native's hermes targets include <hermes/hermes.h> without a target that carries the path.
|
|
26
56
|
include_directories(SYSTEM ${HERMES_SRC}/API ${HERMES_SRC}/public ${NGN_HERMES_BUILD}/lib/config)
|
|
57
|
+
endif()
|
|
27
58
|
|
|
28
59
|
# --- OpenSSL::Crypto -----------------------------------------------------------------------------
|
|
29
60
|
# ReactCxxPlatform's DevServerHelper hashes a device id with SHA256_Init/Update/Final and nothing
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// (CFBundleDisplayName, else CFBundleName). A dev run's binary has no bundle: its id and name are
|
|
7
7
|
// the app's own (app.json's), and its versions null.
|
|
8
8
|
// - NgNativeDevice: brand and manufacturer "Apple", modelName (the Mac's marketing name, else its
|
|
9
|
-
// model identifier), modelId ("Mac15,3"), osName "macOS", osVersion, osBuildId, deviceName,
|
|
9
|
+
// model identifier), modelId ("Mac15,3"), osName ("macOS"), osVersion, osBuildId, deviceName,
|
|
10
10
|
// totalMemory, supportedCpuArchitectures, isDevice true (a Mac is never a simulator) and
|
|
11
11
|
// deviceType 3, expo-device's DESKTOP.
|
|
12
12
|
#pragma once
|
|
@@ -47,6 +47,7 @@ struct MachineFacts {
|
|
|
47
47
|
|
|
48
48
|
// `appId` and `appName` stand in for what a bundle with no Info.plist does not have.
|
|
49
49
|
std::shared_ptr<NativeModule> makeApplicationModule(BundleFacts bundle, std::string appId, std::string appName);
|
|
50
|
-
|
|
50
|
+
// `osName` is the host OS's name (HostOs).
|
|
51
|
+
std::shared_ptr<NativeModule> makeDeviceModule(MachineFacts machine, std::string osName);
|
|
51
52
|
|
|
52
53
|
} // namespace ngn
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
// The bar the app sends is the whole merged bar, its defaults included. An item with a `menuRole`
|
|
6
6
|
// is the OS's own command unless the app marks it `handled`; every other item is the app's, and
|
|
7
7
|
// choosing it sends `menuSelect` with its id. Shortcuts match a key press before the menus see it;
|
|
8
|
-
// one on an editing key (
|
|
8
|
+
// one on an editing key (the OS's primary modifier with Z, X, C, V or A: Cmd-Z on macOS) still goes
|
|
9
|
+
// on to a focused text input, which owns it.
|
|
9
10
|
#pragma once
|
|
10
11
|
|
|
11
12
|
#include "ngn/default-menu.h"
|
|
@@ -26,14 +27,6 @@ namespace ngn {
|
|
|
26
27
|
|
|
27
28
|
using facebook::react::SurfaceId;
|
|
28
29
|
|
|
29
|
-
// A key press: the key as the web names it (a character, or "ArrowLeft", "Enter", "F5"...) and the
|
|
30
|
-
// modifiers held (MenuModifier).
|
|
31
|
-
struct KeyChord {
|
|
32
|
-
std::string key;
|
|
33
|
-
unsigned modifiers{0};
|
|
34
|
-
bool operator==(const KeyChord &) const = default;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
30
|
// The entries of a menu as the app sends them (a context menu's, or one group's items).
|
|
38
31
|
std::vector<MenuItem> parseMenu(const folly::dynamic &entries);
|
|
39
32
|
// The app's whole bar, with the host's Developer menu before Help when `options.developer`.
|
|
@@ -46,9 +39,10 @@ enum class NavigationInput { MouseButton4, MouseButton5, SwipeLeft, SwipeRight }
|
|
|
46
39
|
|
|
47
40
|
// The OS's back and forward inputs: mouse buttons 4 and 5, a swipe (right goes back in a
|
|
48
41
|
// left-to-right layout and left in a right-to-left one, as a page follows the fingers and as Safari
|
|
49
|
-
// swaps them), and Cmd-[ and Cmd-]
|
|
42
|
+
// swaps them), and the OS's back and forward keys (Cmd-[ and Cmd-] on macOS, where Cmd-Left stays
|
|
43
|
+
// with text editing).
|
|
50
44
|
std::optional<NavigationDirection> navigationFor(NavigationInput input, bool rightToLeft = false);
|
|
51
|
-
std::optional<NavigationDirection> navigationFor(const KeyChord &chord);
|
|
45
|
+
std::optional<NavigationDirection> navigationFor(const KeyChord &chord, const HostOs &os);
|
|
52
46
|
|
|
53
47
|
// A window's back and forward history, as the app's router reports it (`setHistory`): the titles
|
|
54
48
|
// of the entries behind and ahead, nearest first.
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
// The menu bar every desktop app gets at launch, before any JavaScript runs:
|
|
2
|
-
// Quit, File's Close Window and Print... (which prints the
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// The menu bar every desktop app gets at launch, before any JavaScript runs: its OS's (HostOs's
|
|
2
|
+
// menuBar). On macOS, the app menu with Quit, File's Close Window and Print... (which prints the
|
|
3
|
+
// key window), the standard text editing commands, View's Back, Forward and Show Sidebar, the
|
|
4
|
+
// window commands and, for a bundle from a dev server, the developer commands. A backend draws it
|
|
5
|
+
// and maps each command to the toolkit's own. The app's own bar replaces it once the app sets one
|
|
6
|
+
// (app-menus.h).
|
|
5
7
|
#pragma once
|
|
6
8
|
|
|
9
|
+
#include "ngn/host-os.h"
|
|
10
|
+
|
|
7
11
|
#include <string>
|
|
8
12
|
#include <vector>
|
|
9
13
|
|
|
@@ -42,8 +46,8 @@ enum class MenuCommand {
|
|
|
42
46
|
AppItem,
|
|
43
47
|
};
|
|
44
48
|
|
|
45
|
-
// The key equivalent's modifiers, as a bitmask
|
|
46
|
-
//
|
|
49
|
+
// The key equivalent's modifiers, as a bitmask: Command is the web's `meta` key and Option its
|
|
50
|
+
// `alt`. Which one is the OS's primary modifier is HostOs's primaryModifier.
|
|
47
51
|
enum MenuModifier : unsigned {
|
|
48
52
|
Command = 1 << 0,
|
|
49
53
|
Shift = 1 << 1,
|
|
@@ -81,9 +85,15 @@ struct DefaultMenuOptions {
|
|
|
81
85
|
std::string appName;
|
|
82
86
|
// Adds the Developer menu (Reload) for a bundle from a dev server.
|
|
83
87
|
bool developer{false};
|
|
88
|
+
// The OS whose menu bar it is, and whose primary modifier and back and forward keys the app's
|
|
89
|
+
// menus and shortcuts follow.
|
|
90
|
+
HostOs os;
|
|
84
91
|
};
|
|
85
92
|
|
|
93
|
+
// The OS's bar: `options.os.menuBar`.
|
|
86
94
|
std::vector<MenuItem> defaultMenuBar(const DefaultMenuOptions &options);
|
|
95
|
+
// macOS's bar (HostOs's menuBar for macOS).
|
|
96
|
+
std::vector<MenuItem> macOSMenuBar(const DefaultMenuOptions &options);
|
|
87
97
|
|
|
88
98
|
// The item with this command anywhere in `menus`, or null.
|
|
89
99
|
const MenuItem *findMenuItem(const std::vector<MenuItem> &menus, MenuCommand command);
|
|
@@ -78,11 +78,6 @@ class PrefixedSecretStore final : public SecretStore {
|
|
|
78
78
|
std::set<std::pair<std::string, std::string>> written_;
|
|
79
79
|
};
|
|
80
80
|
|
|
81
|
-
// Whether the app can use the Data Protection keychain: its signature has a Team ID, and an
|
|
82
|
-
// entitlement that gives it a keychain access group (an application identifier, as a Mac App Store
|
|
83
|
-
// build has, or keychain-access-groups). Without one the keychain refuses it (errSecMissingEntitlement).
|
|
84
|
-
bool usesDataProtectionKeychain(const std::string &teamId, const std::set<std::string> &entitlements);
|
|
85
|
-
|
|
86
81
|
// The service items go under when the call names none: the app's own.
|
|
87
82
|
std::shared_ptr<NativeModule> makeSecureStoreModule(std::shared_ptr<SecretStore> store, std::string defaultService);
|
|
88
83
|
bool secureStoreKeyValid(const std::string &key);
|