@ng-native/desktop 0.23.0 → 0.24.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.
Files changed (54) hide show
  1. package/native/CMakeLists.txt +3 -2
  2. package/native/appkit/CMakeLists.txt +25 -4
  3. package/native/appkit/camera-sheet.h +59 -0
  4. package/native/appkit/camera-sheet.mm +344 -0
  5. package/native/appkit/camera-view.mm +5 -1
  6. package/native/appkit/camera.h +22 -0
  7. package/native/appkit/camera.mm +203 -69
  8. package/native/appkit/cg-canvas.h +8 -1
  9. package/native/appkit/cg-canvas.mm +166 -21
  10. package/native/appkit/header-toolbar.mm +4 -1
  11. package/native/appkit/host-view.mm +29 -1
  12. package/native/appkit/main.mm +29 -69
  13. package/native/appkit/photo-library.mm +6 -6
  14. package/native/appkit/surface-view.mm +5 -1
  15. package/native/appkit/svg-view.h +2 -1
  16. package/native/appkit/svg-view.mm +49 -3
  17. package/native/appkit/tab-walk.h +31 -0
  18. package/native/appkit/tab-walk.mm +64 -0
  19. package/native/appkit/text-input-field.h +5 -0
  20. package/native/appkit/text-input-field.mm +101 -20
  21. package/native/appkit/text-layout.h +1 -1
  22. package/native/appkit/text-layout.mm +16 -8
  23. package/native/appkit/web-view-component.h +4 -3
  24. package/native/appkit/web-view-component.mm +8 -2
  25. package/native/appkit/web-view.mm +7 -0
  26. package/native/core/include/ngn/app-menus.h +8 -3
  27. package/native/core/include/ngn/back-swipe.h +16 -7
  28. package/native/core/include/ngn/camera.h +103 -9
  29. package/native/core/include/ngn/core-modules.h +3 -0
  30. package/native/core/include/ngn/dom-web-view.h +53 -0
  31. package/native/core/include/ngn/photo-library.h +7 -3
  32. package/native/core/include/ngn/runtime.h +10 -8
  33. package/native/core/include/ngn/safe-areas.h +5 -0
  34. package/native/core/include/ngn/surface-metrics.h +51 -0
  35. package/native/core/include/ngn/svg.h +49 -8
  36. package/native/core/include/ngn/text-input.h +9 -0
  37. package/native/core/include/ngn/web-view.h +6 -2
  38. package/native/core/src/app-menus.cpp +10 -3
  39. package/native/core/src/back-swipe.cpp +12 -5
  40. package/native/core/src/dom-web-view.cpp +45 -0
  41. package/native/core/src/libraries/rnsvg.cpp +13 -0
  42. package/native/core/src/modules/app-modules.cpp +20 -13
  43. package/native/core/src/modules/camera.cpp +203 -23
  44. package/native/core/src/modules/photo-library.cpp +22 -8
  45. package/native/core/src/mounting-manager.cpp +4 -0
  46. package/native/core/src/runtime.cpp +6 -8
  47. package/native/core/src/safe-areas.cpp +7 -0
  48. package/native/core/src/svg.cpp +324 -17
  49. package/native/core/src/text-input.cpp +13 -0
  50. package/native/core/src/web-view.cpp +1 -1
  51. package/native/scripts/build.sh +5 -1
  52. package/native/scripts/launch-probe.sh +60 -0
  53. package/package.json +2 -2
  54. package/prebuilt.json +6 -6
@@ -648,6 +648,79 @@ bool listed(const std::vector<std::string> &list, const char *name) {
648
648
  return std::find(list.begin(), list.end(), name) != list.end();
649
649
  }
650
650
 
651
+ // A path as lines, for text set along it, measured from its start.
652
+ struct TextTrack {
653
+ struct Line {
654
+ double x0, y0, x1, y1, length;
655
+ };
656
+ std::vector<Line> lines;
657
+ double length{0};
658
+
659
+ // The point `distance` along the track and its direction there in radians, the next line's at a
660
+ // corner; nothing off the track, whose very end is off it, as Chrome places glyphs.
661
+ std::optional<std::array<double, 3>> at(double distance) const {
662
+ if (distance < 0) {
663
+ return std::nullopt;
664
+ }
665
+ double from = 0;
666
+ for (const auto &l : lines) {
667
+ if (distance < from + l.length) {
668
+ double t = (distance - from) / l.length;
669
+ return std::array<double, 3>{l.x0 + (l.x1 - l.x0) * t, l.y0 + (l.y1 - l.y0) * t, std::atan2(l.y1 - l.y0, l.x1 - l.x0)};
670
+ }
671
+ from += l.length;
672
+ }
673
+ return std::nullopt;
674
+ }
675
+ };
676
+
677
+ // `path` as lines, each curve as 128, in order or reversed. A move between subpaths adds no length.
678
+ TextTrack textTrack(const SvgPath &path, bool reversed) {
679
+ TextTrack track;
680
+ double x = 0, y = 0, startX = 0, startY = 0;
681
+ auto line = [&](double toX, double toY) {
682
+ track.lines.push_back({x, y, toX, toY, std::hypot(toX - x, toY - y)});
683
+ x = toX;
684
+ y = toY;
685
+ };
686
+ for (const auto &s : path.segments) {
687
+ const double *p = s.points;
688
+ switch (s.op) {
689
+ case SvgPath::Op::Move:
690
+ x = startX = p[0];
691
+ y = startY = p[1];
692
+ break;
693
+ case SvgPath::Op::Line:
694
+ line(p[0], p[1]);
695
+ break;
696
+ case SvgPath::Op::Cubic: {
697
+ double x0 = x, y0 = y;
698
+ constexpr int steps = 128;
699
+ for (int i = 1; i <= steps; ++i) {
700
+ double t = static_cast<double>(i) / steps, u = 1 - t;
701
+ double a = u * u * u, b = 3 * u * u * t, c = 3 * u * t * t, d = t * t * t;
702
+ line(a * x0 + b * p[0] + c * p[2] + d * p[4], a * y0 + b * p[1] + c * p[3] + d * p[5]);
703
+ }
704
+ break;
705
+ }
706
+ case SvgPath::Op::Close:
707
+ line(startX, startY);
708
+ break;
709
+ }
710
+ }
711
+ if (reversed) {
712
+ std::reverse(track.lines.begin(), track.lines.end());
713
+ for (auto &l : track.lines) {
714
+ std::swap(l.x0, l.x1);
715
+ std::swap(l.y0, l.y1);
716
+ }
717
+ }
718
+ for (const auto &l : track.lines) {
719
+ track.length += l.length;
720
+ }
721
+ return track;
722
+ }
723
+
651
724
  // The presentation an element draws with, after inheritance.
652
725
  struct Style {
653
726
  SvgBrush fill{.type = SvgBrush::Type::Color, .argb = 0xff000000};
@@ -665,6 +738,7 @@ struct Style {
665
738
  double fontSize{12};
666
739
  std::string fontFamily;
667
740
  std::string fontWeight;
741
+ std::string textAnchor{"start"};
668
742
  // The attributes set somewhere above or on the element, which its children inherit.
669
743
  std::unordered_set<std::string> list;
670
744
  };
@@ -757,6 +831,7 @@ class Renderer {
757
831
  s.fontSize = parent.fontSize;
758
832
  s.fontFamily = e.fontFamily.empty() ? parent.fontFamily : e.fontFamily;
759
833
  s.fontWeight = e.fontWeight.empty() ? parent.fontWeight : e.fontWeight;
834
+ s.textAnchor = e.textAnchor.empty() ? parent.textAnchor : e.textAnchor;
760
835
  if (e.fontSize.set) {
761
836
  s.fontSize = resolveIn(e.fontSize, parent.fontSize, parent.fontSize);
762
837
  }
@@ -838,12 +913,21 @@ class Renderer {
838
913
  }
839
914
  }
840
915
 
916
+ // A foreignObject's box: all of the viewport where it says nothing, as react-native-svg's
917
+ // ForeignObject defaults to 0%, 0%, 100% and 100%.
918
+ SvgRect foreignBox(const SvgElement &e) const {
919
+ return {length(e, "x", Axis::X), length(e, "y", Axis::Y), length(e, "width", Axis::X, vw_), length(e, "height", Axis::Y, vh_)};
920
+ }
921
+
841
922
  // What `node` covers in its own user space (before its own transform), for a gradient's or a
842
923
  // mask's objectBoundingBox.
843
924
  std::optional<SvgRect> bounds(const SvgNode &node) const {
844
925
  if (auto p = shape(node.element)) {
845
926
  return p->bounds();
846
927
  }
928
+ if (node.element.kind == SvgKind::ForeignObject) {
929
+ return foreignBox(node.element);
930
+ }
847
931
  if (node.element.kind != SvgKind::Group) {
848
932
  return std::nullopt;
849
933
  }
@@ -1111,12 +1195,23 @@ class Renderer {
1111
1195
  }
1112
1196
  break;
1113
1197
  }
1114
- case SvgKind::Text:
1115
- case SvgKind::TSpan: {
1116
- double x = 0, y = 0;
1117
- drawText(node, style, x, y);
1198
+ case SvgKind::ForeignObject: {
1199
+ // Its views, at their frames from its corner, cut to its box, as react-native-svg on iOS
1200
+ // draws them.
1201
+ SvgRect box = foreignBox(e);
1202
+ if (e.view != -1 && box.width > 0 && box.height > 0) {
1203
+ canvas_->save();
1204
+ canvas_->concat(SvgMatrix::translate(box.x, box.y));
1205
+ canvas_->clip(rectPath(0, 0, box.width, box.height), false);
1206
+ canvas_->views(e.view);
1207
+ canvas_->restore();
1208
+ }
1118
1209
  break;
1119
1210
  }
1211
+ case SvgKind::Text:
1212
+ case SvgKind::TSpan:
1213
+ drawText(node, style);
1214
+ break;
1120
1215
  default:
1121
1216
  break;
1122
1217
  }
@@ -1410,32 +1505,205 @@ class Renderer {
1410
1505
  }
1411
1506
  }
1412
1507
 
1413
- // A text or a span: its own position, if it sets one, then its characters, then its spans, each
1414
- // starting where the last one ended.
1415
- void drawText(const SvgNode &node, const Style &style, double &x, double &y) {
1508
+ // Text is laid out before it is drawn: runs of characters in chunks, as SVG has them, each chunk
1509
+ // set back by its anchor once its advance is known.
1510
+ struct TextRun {
1511
+ std::string text;
1512
+ double x{0}, y{0}, advance{0};
1513
+ double fontSize{12};
1514
+ std::string fontFamily, fontWeight;
1515
+ std::optional<SvgPaint> fill;
1516
+ // The spans and textPath it is in with an opacity below 1, outermost first, which draw through
1517
+ // no drawNode of their own: each a group, numbered in its layout, and its opacity.
1518
+ std::vector<std::pair<int, double>> groups;
1519
+ };
1520
+ struct TextChunk {
1521
+ std::string anchor;
1522
+ std::vector<TextRun> runs;
1523
+ // On a path: the path, and how far along it a run's x of 0 is; a run's y is then off the path.
1524
+ std::shared_ptr<const TextTrack> track;
1525
+ double startOffset{0};
1526
+ };
1527
+ struct TextLayout {
1528
+ std::vector<TextChunk> chunks;
1529
+ double x{0}, y{0};
1530
+ // The next characters start a chunk: an absolute position or a path came before them.
1531
+ bool chunkStarts{true};
1532
+ std::shared_ptr<const TextTrack> track;
1533
+ double startOffset{0};
1534
+ std::vector<std::pair<int, double>> groups;
1535
+ int nextGroup{0};
1536
+ // The x, y, dx and dy for the next character, from the innermost element that sets one and
1537
+ // holds it, and how many characters have been laid out.
1538
+ std::optional<double> pendingX, pendingY, pendingDx, pendingDy;
1539
+ size_t characters{0};
1540
+ };
1541
+
1542
+ static double anchorShift(const TextChunk &chunk) {
1543
+ double advance = chunk.runs.back().x + chunk.runs.back().advance - chunk.runs.front().x;
1544
+ return chunk.anchor == "middle" ? -advance / 2 : chunk.anchor == "end" ? -advance : 0;
1545
+ }
1546
+
1547
+ // Runs are drawn in the order they were laid out, so what a group holds is drawn together: each
1548
+ // group is one layer around its runs, its opacity applied once, as drawNode composites an element.
1549
+ void drawText(const SvgNode &node, const Style &style) {
1550
+ TextLayout layout;
1551
+ layoutText(node, style, layout);
1552
+ std::vector<int> open;
1553
+ for (const auto &chunk : layout.chunks) {
1554
+ double shift = anchorShift(chunk);
1555
+ for (const auto &run : chunk.runs) {
1556
+ bool hidden = std::any_of(run.groups.begin(), run.groups.end(), [](const auto &g) { return g.second <= 0; });
1557
+ if (!run.fill || hidden) {
1558
+ continue;
1559
+ }
1560
+ size_t shared = 0;
1561
+ while (shared < open.size() && shared < run.groups.size() && open[shared] == run.groups[shared].first) {
1562
+ ++shared;
1563
+ }
1564
+ for (; open.size() > shared; open.pop_back()) {
1565
+ canvas_->endLayer();
1566
+ }
1567
+ for (size_t i = shared; i < run.groups.size(); ++i) {
1568
+ canvas_->beginLayer(run.groups[i].second);
1569
+ open.push_back(run.groups[i].first);
1570
+ }
1571
+ drawRun(chunk, run, shift);
1572
+ }
1573
+ }
1574
+ for (; !open.empty(); open.pop_back()) {
1575
+ canvas_->endLayer();
1576
+ }
1577
+ }
1578
+
1579
+ void layoutChildren(const SvgNode &node, const Style &style, TextLayout &out) {
1580
+ for (const auto &child : node.children) {
1581
+ auto kind = child.element.kind;
1582
+ if (!child.element.hidden && (kind == SvgKind::TSpan || kind == SvgKind::Text || kind == SvgKind::TextPath)) {
1583
+ bool group = child.element.opacity < 1;
1584
+ if (group) {
1585
+ out.groups.emplace_back(out.nextGroup++, std::max(0.0, child.element.opacity));
1586
+ }
1587
+ layoutText(child, merge(style, child.element), out);
1588
+ if (group) {
1589
+ out.groups.pop_back();
1590
+ }
1591
+ }
1592
+ }
1593
+ }
1594
+
1595
+ // A text or a span: its own position, if it sets one, then its characters, then what it holds,
1596
+ // each starting where the last ended. An x or a y starts a chunk. On a path, as Chrome sets it,
1597
+ // x and dx are along the path from startOffset, dy is off it, and y places nothing.
1598
+ void layoutText(const SvgNode &node, const Style &style, TextLayout &out) {
1416
1599
  const auto &e = node.element;
1600
+ if (e.kind == SvgKind::TextPath) {
1601
+ layoutTextPath(node, style, out);
1602
+ return;
1603
+ }
1604
+ // An element's positions are its first character's, wherever among what it holds that is, and
1605
+ // one inside it sets them for the same character instead; one with no characters places nothing.
1606
+ auto saved = std::tuple{out.pendingX, out.pendingY, out.pendingDx, out.pendingDy};
1607
+ size_t before = out.characters;
1417
1608
  if (!e.xs.empty()) {
1418
- x = resolve(e.xs[0], Axis::X, style.fontSize);
1609
+ out.pendingX = resolve(e.xs[0], Axis::X, style.fontSize);
1419
1610
  }
1420
1611
  if (!e.ys.empty()) {
1421
- y = resolve(e.ys[0], Axis::Y, style.fontSize);
1612
+ out.pendingY = resolve(e.ys[0], Axis::Y, style.fontSize);
1422
1613
  }
1423
1614
  if (!e.dxs.empty()) {
1424
- x += resolve(e.dxs[0], Axis::X, style.fontSize);
1615
+ out.pendingDx = resolve(e.dxs[0], Axis::X, style.fontSize);
1425
1616
  }
1426
1617
  if (!e.dys.empty()) {
1427
- y += resolve(e.dys[0], Axis::Y, style.fontSize);
1618
+ out.pendingDy = resolve(e.dys[0], Axis::Y, style.fontSize);
1428
1619
  }
1429
1620
  if (!e.content.empty()) {
1430
- auto fill = paint(style.fill, style.fillOpacity, style, std::nullopt);
1431
- x += canvas_->text(e.content, x, y, style.fontSize, style.fontFamily, style.fontWeight, fill ? &*fill : nullptr);
1621
+ placeNextCharacter(out);
1622
+ if (out.chunkStarts) {
1623
+ out.chunks.push_back({.anchor = style.textAnchor, .track = out.track, .startOffset = out.startOffset});
1624
+ out.chunkStarts = false;
1625
+ }
1626
+ double advance = canvas_->measureText(e.content, style.fontSize, style.fontFamily, style.fontWeight);
1627
+ out.chunks.back().runs.push_back(
1628
+ {.text = e.content,
1629
+ .x = out.x,
1630
+ .y = out.y,
1631
+ .advance = advance,
1632
+ .fontSize = style.fontSize,
1633
+ .fontFamily = style.fontFamily,
1634
+ .fontWeight = style.fontWeight,
1635
+ .fill = paint(style.fill, style.fillOpacity, style, std::nullopt),
1636
+ .groups = out.groups});
1637
+ out.x += advance;
1638
+ ++out.characters;
1639
+ }
1640
+ layoutChildren(node, style, out);
1641
+ if (out.characters == before) {
1642
+ std::tie(out.pendingX, out.pendingY, out.pendingDx, out.pendingDy) = saved;
1643
+ }
1644
+ }
1645
+
1646
+ // The pending positions applied to the next character: an x or a y starts a chunk; on a path x
1647
+ // and dx are along it from startOffset, dy is off it, and y places nothing.
1648
+ static void placeNextCharacter(TextLayout &out) {
1649
+ if (out.pendingX) {
1650
+ out.x = *out.pendingX;
1651
+ out.chunkStarts = true;
1652
+ }
1653
+ if (out.pendingY && !out.track) {
1654
+ out.y = *out.pendingY;
1655
+ out.chunkStarts = true;
1656
+ }
1657
+ out.x += out.pendingDx.value_or(0);
1658
+ out.y += out.pendingDy.value_or(0);
1659
+ out.pendingX = out.pendingY = out.pendingDx = out.pendingDy = std::nullopt;
1660
+ }
1661
+
1662
+ // A textPath: what it holds along the shape it names, from startOffset, as a chunk of its own;
1663
+ // what follows carries on from the path's end, as Chrome places it. One that names no shape, or
1664
+ // is on a path already, draws nothing.
1665
+ void layoutTextPath(const SvgNode &node, const Style &style, TextLayout &out) {
1666
+ const auto &e = node.element;
1667
+ const SvgNode *target = out.track ? nullptr : named(e.href);
1668
+ auto shapePath = target ? shape(target->element) : std::nullopt;
1669
+ if (!shapePath) {
1670
+ return;
1432
1671
  }
1433
- for (const auto &child : node.children) {
1434
- if (child.element.hidden || (child.element.kind != SvgKind::TSpan && child.element.kind != SvgKind::Text)) {
1672
+ SvgPath path;
1673
+ path.append(*shapePath, target->element.matrix.value_or(SvgMatrix{}));
1674
+ auto track = std::make_shared<const TextTrack>(textTrack(path, e.side == "right"));
1675
+ if (track->length <= 0) {
1676
+ return;
1677
+ }
1678
+ auto offset = e.lengths.find("startOffset");
1679
+ out.track = track;
1680
+ out.startOffset = offset == e.lengths.end() ? 0 : resolveIn(offset->second, track->length, style.fontSize);
1681
+ out.x = out.y = 0;
1682
+ out.chunkStarts = true;
1683
+ layoutChildren(node, style, out);
1684
+ out.track.reset();
1685
+ out.x = track->lines.back().x1;
1686
+ out.y = track->lines.back().y1;
1687
+ out.chunkStarts = true;
1688
+ }
1689
+
1690
+ void drawRun(const TextChunk &chunk, const TextRun &run, double shift) {
1691
+ if (!chunk.track) {
1692
+ canvas_->text(run.text, run.x + shift, run.y, run.fontSize, run.fontFamily, run.fontWeight, *run.fill);
1693
+ return;
1694
+ }
1695
+ // Each glyph at the point its middle reaches along the path, turned with the path there, from
1696
+ // where the shaped run has it and as it shaped it, so kerning and joined forms are kept.
1697
+ for (const auto &glyph : canvas_->glyphClusters(run.text, run.fontSize, run.fontFamily, run.fontWeight)) {
1698
+ auto at = chunk.track->at(chunk.startOffset + shift + run.x + glyph.x + glyph.advance / 2);
1699
+ if (!at) {
1435
1700
  continue;
1436
1701
  }
1437
- Style inner = merge(style, child.element);
1438
- drawText(child, inner, x, y);
1702
+ double cos = std::cos((*at)[2]), sin = std::sin((*at)[2]);
1703
+ canvas_->save();
1704
+ canvas_->concat({cos, sin, -sin, cos, (*at)[0], (*at)[1]});
1705
+ canvas_->glyphCluster(glyph, -glyph.advance / 2, run.y, *run.fill);
1706
+ canvas_->restore();
1439
1707
  }
1440
1708
  }
1441
1709
 
@@ -1826,6 +2094,20 @@ std::optional<SvgElement> SvgDrawings::element(const ViewTree &tree, Tag tag) co
1826
2094
  }
1827
2095
 
1828
2096
  void SvgDrawings::changed(const ViewTree &tree, Tag tag) {
2097
+ if (auto e = element(tree, tag); e && e->kind == SvgKind::ForeignObject) {
2098
+ foreign_.insert(tag);
2099
+ }
2100
+ mark(tree, tag, false);
2101
+ repaintAbove(tree, tag);
2102
+ }
2103
+
2104
+ void SvgDrawings::relaidOut(const ViewTree &tree, Tag tag) {
2105
+ repaintAbove(tree, tag);
2106
+ }
2107
+
2108
+ // Marks the svg `tag` is an element of, if any, to be drawn again: when its document changed, or
2109
+ // always with `repaint`.
2110
+ void SvgDrawings::mark(const ViewTree &tree, Tag tag, bool repaint) {
1829
2111
  for (Tag at = tag; at != -1;) {
1830
2112
  auto e = element(tree, at);
1831
2113
  if (!e) {
@@ -1833,6 +2115,9 @@ void SvgDrawings::changed(const ViewTree &tree, Tag tag) {
1833
2115
  }
1834
2116
  if (e->kind == SvgKind::Svg) {
1835
2117
  dirty_.insert(at);
2118
+ if (repaint) {
2119
+ repaint_.insert(at);
2120
+ }
1836
2121
  return;
1837
2122
  }
1838
2123
  const auto *found = tree.find(at);
@@ -1840,9 +2125,23 @@ void SvgDrawings::changed(const ViewTree &tree, Tag tag) {
1840
2125
  }
1841
2126
  }
1842
2127
 
2128
+ // A view in a foreignObject, or the foreignObject itself, changed: each svg that draws it draws
2129
+ // again, though its document is the same.
2130
+ void SvgDrawings::repaintAbove(const ViewTree &tree, Tag tag) {
2131
+ if (foreign_.empty()) {
2132
+ return;
2133
+ }
2134
+ for (const auto *found = tree.find(tag); found != nullptr; found = tree.find(found->parent)) {
2135
+ if (foreign_.contains(found->view.tag)) {
2136
+ mark(tree, found->view.tag, true);
2137
+ }
2138
+ }
2139
+ }
2140
+
1843
2141
  void SvgDrawings::deleted(Tag tag) {
1844
2142
  dirty_.erase(tag);
1845
2143
  drawn_.erase(tag);
2144
+ foreign_.erase(tag);
1846
2145
  }
1847
2146
 
1848
2147
  std::optional<SvgNode> SvgDrawings::node(const ViewTree &tree, Tag tag) const {
@@ -1851,6 +2150,9 @@ std::optional<SvgNode> SvgDrawings::node(const ViewTree &tree, Tag tag) const {
1851
2150
  return std::nullopt;
1852
2151
  }
1853
2152
  SvgNode out{.element = std::move(*e)};
2153
+ if (out.element.kind == SvgKind::ForeignObject) {
2154
+ out.element.view = tag;
2155
+ }
1854
2156
  for (Tag child : tree.find(tag)->children) {
1855
2157
  if (auto c = node(tree, child); c && c->element.kind != SvgKind::Svg) {
1856
2158
  out.children.push_back(std::move(*c));
@@ -1862,6 +2164,8 @@ std::optional<SvgNode> SvgDrawings::node(const ViewTree &tree, Tag tag) const {
1862
2164
  std::vector<SvgDrawings::Drawing> SvgDrawings::settle(const ViewTree &tree) {
1863
2165
  std::vector<Tag> dirty(dirty_.begin(), dirty_.end());
1864
2166
  dirty_.clear();
2167
+ auto repaint = std::move(repaint_);
2168
+ repaint_.clear();
1865
2169
  std::sort(dirty.begin(), dirty.end());
1866
2170
  std::vector<Drawing> out;
1867
2171
  for (Tag tag : dirty) {
@@ -1872,6 +2176,9 @@ std::vector<SvgDrawings::Drawing> SvgDrawings::settle(const ViewTree &tree) {
1872
2176
  auto document = std::make_shared<const SvgDocument>(SvgDocument{.root = std::move(*root)});
1873
2177
  auto known = drawn_.find(tag);
1874
2178
  if (known != drawn_.end() && *known->second == *document) {
2179
+ if (repaint.contains(tag)) {
2180
+ out.push_back({.svg = tag, .document = known->second});
2181
+ }
1875
2182
  continue;
1876
2183
  }
1877
2184
  drawn_[tag] = document;
@@ -63,6 +63,19 @@ TextInputOptions textInputOptions(const DesktopTextInputProps &props) {
63
63
  return options;
64
64
  }
65
65
 
66
+ TextAlignment inputAlignment(std::optional<TextAlignment> alignment, LayoutDirection layoutDirection) {
67
+ if (!alignment) {
68
+ return layoutDirection == LayoutDirection::RightToLeft ? TextAlignment::Right : TextAlignment::Left;
69
+ }
70
+ switch (*alignment) {
71
+ case TextAlignment::Center:
72
+ case TextAlignment::Justified: return *alignment;
73
+ case TextAlignment::Right:
74
+ case TextAlignment::End: return TextAlignment::Right;
75
+ default: return TextAlignment::Left;
76
+ }
77
+ }
78
+
66
79
  std::size_t insertionThatFits(
67
80
  std::size_t current,
68
81
  std::size_t replaced,
@@ -43,7 +43,7 @@ NavigationStep navigationStep(const WebViewConfig &config, const std::string &ur
43
43
  bool userActivated = navigationType == "click" || navigationType == "formsubmit";
44
44
  return userActivated && externalUrlAllowed(url) ? NavigationStep::OpenExternally : NavigationStep::Cancel;
45
45
  }
46
- return NavigationStep::AskApp;
46
+ return config.asksApp ? NavigationStep::AskApp : NavigationStep::Allow;
47
47
  }
48
48
 
49
49
  std::string webViewMessagingScript() {
@@ -12,7 +12,7 @@
12
12
  # --universal arm64 and x86_64 in one binary (default: this machine's architecture)
13
13
  # --debug a Debug build (default: RelWithDebInfo)
14
14
  # --release a Release build without the core tests, as a packaged app ships it
15
- # --test run the core tests after building
15
+ # --test run the core tests after building, and the AppKit view tests when it built them
16
16
  # --no-tests leave the core tests out, as an app's build does: the published package has
17
17
  # none of their sources
18
18
  # --no-debug-info the default RelWithDebInfo build without its debug info, for a host that is
@@ -167,5 +167,9 @@ cmake --log-level=WARNING -G Ninja -S "$native_dir" -B "$BUILD" \
167
167
  nice -n 10 cmake --build "$BUILD" -j "$JOBS" >&2
168
168
  if [ "$run_tests" = 1 ]; then
169
169
  "$BUILD/ngn_core_tests" >&2
170
+ # The AppKit view tests, which a build with the AppKit backend has.
171
+ if [ -x "$BUILD/appkit/ngn_appkit_tests" ]; then
172
+ "$BUILD/appkit/ngn_appkit_tests" >&2
173
+ fi
170
174
  fi
171
175
  echo "$BUILD"
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env bash
2
+ # Launches a built host on a bundle file and checks that it starts: the app commits and the host
3
+ # draws its first frame, then it keeps running for a moment. Fails on a crash or an exit before
4
+ # then, an uncaught JavaScript error, or no first frame in time. Prints the host's log either way.
5
+ #
6
+ # launch-probe.sh <ngn-macos> <bundle.js> [seconds, default 60]
7
+ #
8
+ # A test launch (NGN_TESTS=1): the host keeps its state in a new directory, takes no focus and
9
+ # shows no system prompt, so the probe leaves nothing behind on the machine it runs on.
10
+ set -euo pipefail
11
+ host="${1:?usage: launch-probe.sh <ngn-macos> <bundle.js> [seconds]}"
12
+ bundle="${2:?usage: launch-probe.sh <ngn-macos> <bundle.js> [seconds]}"
13
+ limit="${3:-60}"
14
+
15
+ work="$(mktemp -d)"
16
+ log="$work/host.log"
17
+ pid=""
18
+ cleanup() {
19
+ if [ -n "$pid" ] && kill -0 "$pid" 2> /dev/null; then
20
+ kill "$pid" 2> /dev/null || true
21
+ wait "$pid" 2> /dev/null || true
22
+ fi
23
+ rm -rf "$work"
24
+ }
25
+ trap cleanup EXIT
26
+
27
+ mkdir "$work/state"
28
+ NGN_TESTS=1 NGN_STATE_DIR="$work/state" NGN_RUN_ID="probe-$$" NGN_TESTS_FAKE_SYSTEM_UI=1 NGN_LOG_COMMITS=1 \
29
+ "$host" "$bundle" --title "Launch probe" > "$log" 2>&1 &
30
+ pid=$!
31
+
32
+ fail() {
33
+ echo "launch-probe: $1" >&2
34
+ echo "--- host log ---" >&2
35
+ cat "$log" >&2
36
+ exit 1
37
+ }
38
+
39
+ # An uncaught error reaches React Native's default error handler, which logs it; console.error logs
40
+ # at level 3.
41
+ js_error() {
42
+ grep -qE '\[onJsError called\]|\[js:3\]' "$log"
43
+ }
44
+
45
+ start=$(date +%s)
46
+ while ! grep -q '^\[ngn\] first frame' "$log"; do
47
+ kill -0 "$pid" 2> /dev/null || { wait "$pid" && status=0 || status=$?; fail "the host exited ($status) before its first frame"; }
48
+ js_error && fail "a JavaScript error before the first frame"
49
+ [ $(($(date +%s) - start)) -lt "$limit" ] || fail "no first frame within ${limit}s"
50
+ sleep 0.2
51
+ done
52
+ grep -q '^\[ngn\] commit' "$log" || fail "the first frame came with no commit"
53
+
54
+ # Still running a moment after the first frame: a crash in the commits that follow fails too.
55
+ sleep 3
56
+ kill -0 "$pid" 2> /dev/null || { wait "$pid" && status=0 || status=$?; fail "the host exited ($status) after its first frame"; }
57
+ js_error && fail "a JavaScript error after the first frame"
58
+
59
+ cat "$log"
60
+ echo "launch-probe: $(grep '^\[ngn\] first frame' "$log"), $(grep -c '^\[ngn\] commit' "$log") commits"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-native/desktop",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "description": "The macOS desktop host for Angular Native: React Native's C++ core and Hermes, mounting into AppKit views, and the ng-native-desktop command that builds and launches it.",
5
5
  "keywords": [
6
6
  "angular",
@@ -16,7 +16,7 @@
16
16
  "ng-native-desktop": "./bin/ng-native-desktop.mjs"
17
17
  },
18
18
  "dependencies": {
19
- "@ng-native/device": "0.23.0"
19
+ "@ng-native/device": "0.24.0"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "react-native": "~0.88.0"
package/prebuilt.json CHANGED
@@ -4,8 +4,8 @@
4
4
  {
5
5
  "reactNative": "0.88.0",
6
6
  "flavour": "debug",
7
- "url": "https://github.com/ng-native/ng-native/releases/download/vminor/ng-native-desktop-host-minor-rn-0.88.0-macos-universal-debug.tar.gz",
8
- "sha256": "f69b8e99c19f739f6a8f0039fe92a99a2e3dca7b2523f95541e6943c13678d46",
7
+ "url": "https://github.com/ng-native/ng-native/releases/download/v0.24.0/ng-native-desktop-host-0.24.0-rn-0.88.0-macos-universal-debug.tar.gz",
8
+ "sha256": "511cf3168dd8a613655934d68f9ad574834d510b1d55ef743b39031bf41526c4",
9
9
  "libraries": {
10
10
  "react-native-screens": "4.30.0",
11
11
  "react-native-safe-area-context": "5.10.1",
@@ -13,13 +13,13 @@
13
13
  "react-native-worklets": "0.13.0",
14
14
  "react-native-reanimated": "4.7.1"
15
15
  },
16
- "inputs": "af0e12481a719f97c4ba92eee9317c1207084d2cb6f4eb6affada352019e3f32"
16
+ "inputs": "7fa2f4fd506382258e6a1717b3bd20bacf13e0c0c7753e14326a6396c50722de"
17
17
  },
18
18
  {
19
19
  "reactNative": "0.88.0",
20
20
  "flavour": "release",
21
- "url": "https://github.com/ng-native/ng-native/releases/download/vminor/ng-native-desktop-host-minor-rn-0.88.0-macos-universal.tar.gz",
22
- "sha256": "d4058d91c399452762deef93ea87586e3511c22d249ea9853819ae16ebca7f33",
21
+ "url": "https://github.com/ng-native/ng-native/releases/download/v0.24.0/ng-native-desktop-host-0.24.0-rn-0.88.0-macos-universal.tar.gz",
22
+ "sha256": "0f0c417ebb24b25062696db92a6797585fed117def31ff87e7a4e09e127aeae6",
23
23
  "libraries": {
24
24
  "react-native-screens": "4.30.0",
25
25
  "react-native-safe-area-context": "5.10.1",
@@ -27,7 +27,7 @@
27
27
  "react-native-worklets": "0.13.0",
28
28
  "react-native-reanimated": "4.7.1"
29
29
  },
30
- "inputs": "2521d55a05418e1d949972e0263e34ebd502ef69694a58bf8d45428b4c0d080b"
30
+ "inputs": "62458462c0c914c24a88a151a4af50ad70fbb332a967b81f9d78774da29fef4c"
31
31
  }
32
32
  ]
33
33
  }