@windowkit/appkit 0.16.0 → 0.17.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windowkit/appkit",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "Retained-mode AppKit backend for Node.js: Core Animation (CALayer) layer trees, CoreText layout and drawing, IOSurface presentation, NSMenu, and native control bezels — the macOS half of react-x11.",
5
5
  "author": "Andrey Sidorov <andrey.sidorov@gmail.com>",
6
6
  "license": "MIT",
@@ -43,7 +43,7 @@
43
43
  "install": "node scripts/install.js",
44
44
  "build": "node-gyp rebuild",
45
45
  "demo": "node demo/demo.js",
46
- "test": "node test/app-lifecycle.js && node test/animation.js && node test/accessibility-display.js && node test/ignores-mouse-events.js && node test/surface-blit.js && node test/control-bezels.js && node test/text-features.js && node test/text-coverage.js && node test/text-typesetter.js && node test/text-line-height.js && node test/text-line-width.js && node test/symbols.js && node test/eventkit-permissions.js && node test/calendars.js && node test/calendar-writes.js && node test/screencolor.js && node test/threaded.js && node test/threaded-verbs.js && node test/threaded-frames.js && node test/threaded-resize.js && node test/ending-worker.js && node test/live-resize.js && node test/activation-policy.js"
46
+ "test": "node test/app-lifecycle.js && node test/animation.js && node test/accessibility-display.js && node test/ignores-mouse-events.js && node test/surface-blit.js && node test/round-rect-xy.js && node test/control-bezels.js && node test/text-features.js && node test/text-coverage.js && node test/text-typesetter.js && node test/text-line-height.js && node test/text-line-width.js && node test/symbols.js && node test/eventkit-permissions.js && node test/calendars.js && node test/calendar-writes.js && node test/screencolor.js && node test/threaded.js && node test/threaded-verbs.js && node test/threaded-frames.js && node test/threaded-resize.js && node test/ending-worker.js && node test/live-resize.js && node test/activation-policy.js"
47
47
  },
48
48
  "dependencies": {
49
49
  "node-addon-api": "^8.3.0"
Binary file
package/src/backend.mm CHANGED
@@ -3745,6 +3745,46 @@ static Napi::Value CtxRoundRect(const Napi::CallbackInfo& info) {
3745
3745
  CGPathRelease(p);
3746
3746
  return info.Env().Undefined();
3747
3747
  }
3748
+ // roundRectXY(surface, x, y, w, h, tlx, tly, trx, try, brx, bry, blx, bly)
3749
+ // — a rounded rect whose corners are elliptical, each with its own pair of
3750
+ // radii: canvas's roundRect with `{ x, y }` radii, and CSS's
3751
+ // `border-radius: 40px / 20px`. The caller has scaled them to fit, as
3752
+ // canvas scales them. A corner with no extent on one of its axes is no curve
3753
+ // at all, and is square — drawn as two lines it would cut the corner off
3754
+ // diagonally. Each quarter ellipse is one cubic, its handles a KAPPA of the
3755
+ // radius along each tangent, as WebKit draws an elliptical corner.
3756
+ static Napi::Value CtxRoundRectXY(const Napi::CallbackInfo& info) {
3757
+ CALSurface* s = SurfaceFrom(info[0]);
3758
+ if (!s) return info.Env().Undefined();
3759
+ double v[12];
3760
+ for (int i = 0; i < 12; i++) v[i] = info[i + 1].As<Napi::Number>().DoubleValue();
3761
+ const double x = v[0], y = v[1], r = v[0] + v[2], b = v[1] + v[3];
3762
+ double c[8];
3763
+ for (int i = 0; i < 4; i++) {
3764
+ const bool curved = v[4 + i * 2] > 0 && v[5 + i * 2] > 0;
3765
+ c[i * 2] = curved ? v[4 + i * 2] : 0;
3766
+ c[i * 2 + 1] = curved ? v[5 + i * 2] : 0;
3767
+ }
3768
+ const double tlx = c[0], tly = c[1], trx = c[2], trY = c[3];
3769
+ const double brx = c[4], brY = c[5], blx = c[6], blY = c[7];
3770
+ // how far in from the corner's own point a handle sits, as a fraction of
3771
+ // the radius along it
3772
+ const double k = 1 - 0.5522847498307936;
3773
+ CGMutablePathRef p = CGPathCreateMutable();
3774
+ CGPathMoveToPoint(p, NULL, x + tlx, y);
3775
+ CGPathAddLineToPoint(p, NULL, r - trx, y);
3776
+ if (trx > 0) CGPathAddCurveToPoint(p, NULL, r - trx * k, y, r, y + trY * k, r, y + trY);
3777
+ CGPathAddLineToPoint(p, NULL, r, b - brY);
3778
+ if (brx > 0) CGPathAddCurveToPoint(p, NULL, r, b - brY * k, r - brx * k, b, r - brx, b);
3779
+ CGPathAddLineToPoint(p, NULL, x + blx, b);
3780
+ if (blx > 0) CGPathAddCurveToPoint(p, NULL, x + blx * k, b, x, b - blY * k, x, b - blY);
3781
+ CGPathAddLineToPoint(p, NULL, x, y + tly);
3782
+ if (tlx > 0) CGPathAddCurveToPoint(p, NULL, x, y + tly * k, x + tlx * k, y, x + tlx, y);
3783
+ CGPathCloseSubpath(p);
3784
+ CGContextAddPath(s->ctx, p);
3785
+ CGPathRelease(p);
3786
+ return info.Env().Undefined();
3787
+ }
3748
3788
  static Napi::Value CtxArc(const Napi::CallbackInfo& info) {
3749
3789
  // arc(surface, x, y, r, a0, a1, anticlockwise). Angles live in user
3750
3790
  // space, where canvas's y-down "clockwise" sweep is the INCREASING-angle
@@ -7140,6 +7180,7 @@ void InitBackend(Napi::Env env, Napi::Object exports) {
7140
7180
  BFN("ctxLineTo", CtxLineTo);
7141
7181
  BFN("ctxRect", CtxRect);
7142
7182
  BFN("ctxRoundRect", CtxRoundRect);
7183
+ BFN("ctxRoundRectXY", CtxRoundRectXY);
7143
7184
  BFN("ctxArc", CtxArc);
7144
7185
  BFN("ctxEllipse", CtxEllipse);
7145
7186
  BFN("ctxCurveTo", CtxCurveTo);