@windowkit/appkit 0.27.0 → 0.28.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/README.md
CHANGED
|
@@ -126,7 +126,7 @@ waits on the UI thread (`test/threaded-verbs.js` covers each row):
|
|
|
126
126
|
| from a worker | verbs |
|
|
127
127
|
| --- | --- |
|
|
128
128
|
| unchanged, on the calling thread | surfaces and video surfaces, every `ctx*` (`ctxDrawSymbol` included), layouts and fonts, `symbolSize`, `pasteboardTypeForMIME`, `pasteboardTypeInfo`, `contentTypeFor`, `colorSpace` |
|
|
129
|
-
| a command, answering nothing | `initApp`, `setActivationPolicy`, `setAppName`, `activateApp`, `showWindow`, `hideWindow`, `setWindowFrame`, `setWindowTitle`, `setWindowMinMax`, `setWindowIgnoresMouseEvents`, `invalidateWindowShadow`, `destroyWindow2`, `setCursor`, `setMainMenu`, `setDockMenu`, `setDockBadge`, `cancelUserAttention`, `setStatusItem`, `setStatusItemMenu`, `removeStatusItem`, `registerDropTypes`, `setDropResponse`, `pasteboardWriteText`, `pasteboardClear`, `cancelPanel`, `cancelPopUpMenu`; the test posts `postMouseEvent`, `postKeyEvent`, `postAppleEvent`, `postAccessibilityDisplayChange` |
|
|
129
|
+
| a command, answering nothing | `initApp`, `setActivationPolicy`, `setAppName`, `activateApp`, `showWindow`, `hideWindow`, `setWindowFrame`, `setWindowTitle`, `setWindowMinMax`, `setWindowIgnoresMouseEvents`, `invalidateWindowShadow`, `destroyWindow2`, `setCursor`, `setMainMenu`, `setDockMenu`, `setDockBadge`, `cancelUserAttention`, `setStatusItem`, `setStatusItemMenu`, `removeStatusItem`, `registerDropTypes`, `setDropResponse`, `pasteboardWriteText`, `pasteboardWrite`, `pasteboardClear`, `cancelPanel`, `cancelPopUpMenu`; the test posts `postMouseEvent`, `postKeyEvent`, `postAppleEvent`, `postAccessibilityDisplayChange` |
|
|
130
130
|
| a handle at the call | `createWindow2`, followed by `window-created { handle, windowNumber }`; every event about the window, input included, carries `handle`, so `ev.handle === win` |
|
|
131
131
|
| | `windowRootLayer`, allocated with the window |
|
|
132
132
|
| | `createStatusItem`: its clicks carry the handle, and it is held until `removeStatusItem` |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@windowkit/appkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.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/layer-transform.js && node test/contents-gravity.js && node test/contents-center.js && node test/accessibility-display.js && node test/ignores-mouse-events.js && node test/popup-menu.js && node test/surface-blit.js && node test/surface-faded.js && node test/image-smoothing.js && node test/surface-colorspace.js && node test/video-surface.js && node test/player.js && node test/round-rect-xy.js && node test/clip-rule.js && node test/control-bezels.js && node test/text-features.js && node test/font-from-data.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/text-justify.js && node test/text-scale.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/notifications.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/layer-transform.js && node test/contents-gravity.js && node test/contents-center.js && node test/accessibility-display.js && node test/ignores-mouse-events.js && node test/popup-menu.js && node test/pasteboard-write.js && node test/surface-blit.js && node test/surface-faded.js && node test/image-smoothing.js && node test/surface-colorspace.js && node test/video-surface.js && node test/player.js && node test/round-rect-xy.js && node test/clip-rule.js && node test/radial-gradient.js && node test/control-bezels.js && node test/text-features.js && node test/font-from-data.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/text-justify.js && node test/text-scale.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/notifications.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
|
|
Binary file
|
package/src/backend.mm
CHANGED
|
@@ -4371,16 +4371,9 @@ static Napi::Value CtxFillRects(const Napi::CallbackInfo& info) {
|
|
|
4371
4371
|
return info.Env().Undefined();
|
|
4372
4372
|
}
|
|
4373
4373
|
|
|
4374
|
-
//
|
|
4375
|
-
//
|
|
4376
|
-
static
|
|
4377
|
-
CALSurface* s = SurfaceFrom(info[0]);
|
|
4378
|
-
if (!s) return info.Env().Undefined();
|
|
4379
|
-
double x0 = info[1].As<Napi::Number>().DoubleValue();
|
|
4380
|
-
double y0 = info[2].As<Napi::Number>().DoubleValue();
|
|
4381
|
-
double x1 = info[3].As<Napi::Number>().DoubleValue();
|
|
4382
|
-
double y1 = info[4].As<Napi::Number>().DoubleValue();
|
|
4383
|
-
Napi::Array stopsArr = info[5].As<Napi::Array>();
|
|
4374
|
+
// A gradient's stops, flat as [offset, r, g, b, a, ...] with each offset in
|
|
4375
|
+
// [0, 1], in sRGB: what fillLinearGradient and fillRadialGradient draw.
|
|
4376
|
+
static CGGradientRef GradientOfStops(Napi::Array stopsArr) {
|
|
4384
4377
|
std::vector<CGFloat> locs;
|
|
4385
4378
|
std::vector<CGFloat> comps;
|
|
4386
4379
|
for (uint32_t i = 0; i + 4 < stopsArr.Length(); i += 5) {
|
|
@@ -4394,17 +4387,37 @@ static Napi::Value CtxFillLinearGradient(const Napi::CallbackInfo& info) {
|
|
|
4394
4387
|
CGGradientRef grad = CGGradientCreateWithColorComponents(
|
|
4395
4388
|
cs, comps.data(), locs.data(), locs.size());
|
|
4396
4389
|
CGColorSpaceRelease(cs);
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4390
|
+
return grad;
|
|
4391
|
+
}
|
|
4392
|
+
|
|
4393
|
+
// What a gradient fill is cut to, in a saved state: the rect whose x, y, w
|
|
4394
|
+
// and h start at argument `at` where one follows (fillRect with a gradient
|
|
4395
|
+
// fillStyle), else the current path, which is kept for after.
|
|
4396
|
+
static void ClipForGradient(CALSurface* s, const Napi::CallbackInfo& info,
|
|
4397
|
+
size_t at) {
|
|
4398
|
+
if (info.Length() > at + 3 && info[at].IsNumber()) {
|
|
4399
|
+
CGContextClipToRect(
|
|
4400
|
+
s->ctx, CGRectMake(info[at].As<Napi::Number>().DoubleValue(),
|
|
4401
|
+
info[at + 1].As<Napi::Number>().DoubleValue(),
|
|
4402
|
+
info[at + 2].As<Napi::Number>().DoubleValue(),
|
|
4403
|
+
info[at + 3].As<Napi::Number>().DoubleValue()));
|
|
4405
4404
|
} else {
|
|
4406
4405
|
KeepPathAround(s->ctx, ^{ CGContextClip(s->ctx); });
|
|
4407
4406
|
}
|
|
4407
|
+
}
|
|
4408
|
+
|
|
4409
|
+
// fillLinearGradient(surface, x0, y0, x1, y1, stops [offset,r,g,b,a,...],
|
|
4410
|
+
// mode: 0 = fill current path, 1 = fill rect args follow)
|
|
4411
|
+
static Napi::Value CtxFillLinearGradient(const Napi::CallbackInfo& info) {
|
|
4412
|
+
CALSurface* s = SurfaceFrom(info[0]);
|
|
4413
|
+
if (!s) return info.Env().Undefined();
|
|
4414
|
+
double x0 = info[1].As<Napi::Number>().DoubleValue();
|
|
4415
|
+
double y0 = info[2].As<Napi::Number>().DoubleValue();
|
|
4416
|
+
double x1 = info[3].As<Napi::Number>().DoubleValue();
|
|
4417
|
+
double y1 = info[4].As<Napi::Number>().DoubleValue();
|
|
4418
|
+
CGGradientRef grad = GradientOfStops(info[5].As<Napi::Array>());
|
|
4419
|
+
CGContextSaveGState(s->ctx);
|
|
4420
|
+
ClipForGradient(s, info, 6);
|
|
4408
4421
|
CGContextDrawLinearGradient(
|
|
4409
4422
|
s->ctx, grad, CGPointMake(x0, y0), CGPointMake(x1, y1),
|
|
4410
4423
|
kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
|
|
@@ -4413,6 +4426,34 @@ static Napi::Value CtxFillLinearGradient(const Napi::CallbackInfo& info) {
|
|
|
4413
4426
|
return info.Env().Undefined();
|
|
4414
4427
|
}
|
|
4415
4428
|
|
|
4429
|
+
// fillRadialGradient(surface, x0, y0, r0, x1, y1, r1,
|
|
4430
|
+
// stops [offset,r,g,b,a,...], x?, y?, w?, h?)
|
|
4431
|
+
//
|
|
4432
|
+
// canvas's createRadialGradient: the colours spread from the start circle to
|
|
4433
|
+
// the end one, and the end colours carried on past both, as canvas extends
|
|
4434
|
+
// them — the current path filled with it, or the rect that follows the
|
|
4435
|
+
// stops. CoreGraphics' two-circle gradient is canvas's: the same cone where
|
|
4436
|
+
// the circles do not nest, painted from the end circle in.
|
|
4437
|
+
static Napi::Value CtxFillRadialGradient(const Napi::CallbackInfo& info) {
|
|
4438
|
+
CALSurface* s = SurfaceFrom(info[0]);
|
|
4439
|
+
if (!s) return info.Env().Undefined();
|
|
4440
|
+
double x0 = info[1].As<Napi::Number>().DoubleValue();
|
|
4441
|
+
double y0 = info[2].As<Napi::Number>().DoubleValue();
|
|
4442
|
+
double r0 = info[3].As<Napi::Number>().DoubleValue();
|
|
4443
|
+
double x1 = info[4].As<Napi::Number>().DoubleValue();
|
|
4444
|
+
double y1 = info[5].As<Napi::Number>().DoubleValue();
|
|
4445
|
+
double r1 = info[6].As<Napi::Number>().DoubleValue();
|
|
4446
|
+
CGGradientRef grad = GradientOfStops(info[7].As<Napi::Array>());
|
|
4447
|
+
CGContextSaveGState(s->ctx);
|
|
4448
|
+
ClipForGradient(s, info, 8);
|
|
4449
|
+
CGContextDrawRadialGradient(
|
|
4450
|
+
s->ctx, grad, CGPointMake(x0, y0), r0, CGPointMake(x1, y1), r1,
|
|
4451
|
+
kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
|
|
4452
|
+
CGContextRestoreGState(s->ctx);
|
|
4453
|
+
CGGradientRelease(grad);
|
|
4454
|
+
return info.Env().Undefined();
|
|
4455
|
+
}
|
|
4456
|
+
|
|
4416
4457
|
// drawSurface(dst, src, sx, sy, sw, sh, dx, dy, dw, dh)
|
|
4417
4458
|
static Napi::Value CtxDrawSurface(const Napi::CallbackInfo& info) {
|
|
4418
4459
|
CALSurface* dst = SurfaceFrom(info[0]);
|
|
@@ -7221,6 +7262,33 @@ static NSArray<NSPasteboardItem*>* BuildPasteboardItems(const PbItemsSpec& spec,
|
|
|
7221
7262
|
return items;
|
|
7222
7263
|
}
|
|
7223
7264
|
|
|
7265
|
+
// pasteboardWrite(items) — the general pasteboard's contents, replaced by
|
|
7266
|
+
// any number of representations at once: `{ 'public.png': bytes,
|
|
7267
|
+
// 'public.utf8-plain-text': 'caption' }` is one item a paste may take
|
|
7268
|
+
// either way, and an array is one entry per item. The same shape a drag
|
|
7269
|
+
// takes, so a copy and a drag of one payload are one vocabulary. Values are
|
|
7270
|
+
// strings or bytes (Buffer, typed array, ArrayBuffer); null is dropped,
|
|
7271
|
+
// since nothing would ever be asked to provide it. Read on the calling
|
|
7272
|
+
// thread, written on the UI thread, like pasteboardWriteText.
|
|
7273
|
+
static Napi::Value PbWriteFn(const Napi::CallbackInfo& info) {
|
|
7274
|
+
Napi::Env env = info.Env();
|
|
7275
|
+
if (info.Length() < 1 || !info[0].IsObject()) {
|
|
7276
|
+
Napi::TypeError::New(env,
|
|
7277
|
+
"pasteboardWrite(items): items is { [type]: string "
|
|
7278
|
+
"| bytes } or an array of them")
|
|
7279
|
+
.ThrowAsJavaScriptException();
|
|
7280
|
+
return env.Undefined();
|
|
7281
|
+
}
|
|
7282
|
+
PbItemsSpec spec = ParsePasteboardItems(env, info[0], false);
|
|
7283
|
+
CALOnUI(^{
|
|
7284
|
+
NSPasteboard* pb = NSPasteboard.generalPasteboard;
|
|
7285
|
+
[pb clearContents];
|
|
7286
|
+
[pb writeObjects:BuildPasteboardItems(spec, nil)];
|
|
7287
|
+
PublishPasteboardCount();
|
|
7288
|
+
});
|
|
7289
|
+
return env.Undefined();
|
|
7290
|
+
}
|
|
7291
|
+
|
|
7224
7292
|
// The drag image, from either bitmap this addon deals in: `surface`, a
|
|
7225
7293
|
// surface handle (the renderer's own paint, its scale known, its pixels
|
|
7226
7294
|
// copied as they are at the call), or `image`, a CGImage External — or the
|
|
@@ -7954,6 +8022,7 @@ void InitBackend(Napi::Env env, Napi::Object exports) {
|
|
|
7954
8022
|
BFN("ctxClearRect", CtxClearRect);
|
|
7955
8023
|
BFN("ctxFillRects", CtxFillRects);
|
|
7956
8024
|
BFN("ctxFillLinearGradient", CtxFillLinearGradient);
|
|
8025
|
+
BFN("ctxFillRadialGradient", CtxFillRadialGradient);
|
|
7957
8026
|
BFN("ctxDrawSurface", CtxDrawSurface);
|
|
7958
8027
|
BFN("ctxDrawSurfaceFaded", CtxDrawSurfaceFaded);
|
|
7959
8028
|
BFN("ctxPutImageData", CtxPutImageData);
|
|
@@ -7987,6 +8056,7 @@ void InitBackend(Napi::Env env, Napi::Object exports) {
|
|
|
7987
8056
|
BFN("layoutCaret", LayoutCaret);
|
|
7988
8057
|
BFN("layoutCoverage", LayoutCoverage);
|
|
7989
8058
|
BFN("pasteboardWriteText", PbWriteTextFn);
|
|
8059
|
+
BFN("pasteboardWrite", PbWriteFn);
|
|
7990
8060
|
BFN("pasteboardReadText", PbReadTextFn);
|
|
7991
8061
|
BFN("pasteboardClear", PbClearFn);
|
|
7992
8062
|
BFN("pasteboardChangeCount", PbChangeCountFn);
|