@windowkit/appkit 0.23.0 → 0.25.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 +14 -0
- package/package.json +2 -2
- package/prebuilds/darwin-arm64/calayers.node +0 -0
- package/prebuilds/darwin-x64/calayers.node +0 -0
- package/src/addon.mm +59 -2
package/README.md
CHANGED
|
@@ -417,6 +417,20 @@ positive angle turns clockwise and a positive translation moves down, with no si
|
|
|
417
417
|
change on the way in. A matrix of the wrong length or with a number that is not finite
|
|
418
418
|
is a `TypeError`, and nothing is applied.
|
|
419
419
|
|
|
420
|
+
**Contents gravity.** `setLayerProps`' `contentsGravity` is how a layer's contents sit in
|
|
421
|
+
bounds that are not their size: `resize`, Core Animation's default, stretches them;
|
|
422
|
+
`resizeAspect` and `resizeAspectFill` scale them keeping their shape; `center`, `top`,
|
|
423
|
+
`bottom`, `left`, `right`, `topLeft`, `topRight`, `bottomLeft` and `bottomRight` leave
|
|
424
|
+
them at their size, anchored there. A window or a pane whose bounds grow before a frame
|
|
425
|
+
of the new size is drawn shows its last frame by this: stretched by default — a page's
|
|
426
|
+
left column scaled a little, then drawn back at its size — or anchored, a strip of what
|
|
427
|
+
is under it showing where the new frame will be. The names are as they look, `top` being
|
|
428
|
+
the window's top. Core Animation's own are in the layer's space, where `top` is the
|
|
429
|
+
greatest y, which under a window's geometry-flipped root is the bottom of the screen, so
|
|
430
|
+
the bridge turns them over where the layer's space is flipped; `presentationValue(layer,
|
|
431
|
+
'contentsGravity')` answers Core Animation's name, `bottomLeft` for a `topLeft` here.
|
|
432
|
+
Any other name, or a value that is not one, is a `TypeError`, and nothing is applied.
|
|
433
|
+
|
|
420
434
|
**`native.transformForms()`** — `['translate', 'rotate', 'scale', 'matrix', 'matrix3d']`:
|
|
421
435
|
the forms a transform takes on its way in. A caller that hands over matrices
|
|
422
436
|
feature-detects `matrix` here; before 0.19 an object holding one was read as no transform
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@windowkit/appkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.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/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-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/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-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/addon.mm
CHANGED
|
@@ -583,8 +583,49 @@ struct LayerPropsSpec {
|
|
|
583
583
|
NSString* name = nil;
|
|
584
584
|
id mask = nil; // a layer target; nil clears
|
|
585
585
|
CATransform3D transform = CATransform3DIdentity;
|
|
586
|
+
bool hasGravity = false, badGravity = false;
|
|
587
|
+
NSString* gravity = nil; // as named: the window's top is `top`
|
|
586
588
|
};
|
|
587
589
|
|
|
590
|
+
// `contentsGravity`: how a layer's contents sit in bounds that are not
|
|
591
|
+
// their size. Core Animation's default stretches them to the bounds, which
|
|
592
|
+
// is what a window shows while it waits for a frame of its new size; the
|
|
593
|
+
// others leave them at their size, anchored. Named as they look — `top` is
|
|
594
|
+
// the window's top — where Core Animation's names are the layer's own
|
|
595
|
+
// space, whose `top` is its greatest y: under the window's geometry-flipped
|
|
596
|
+
// root, the bottom of the screen (`CALGravity`).
|
|
597
|
+
static bool CALGravityKnown(NSString* name) {
|
|
598
|
+
static NSSet* known = [NSSet setWithArray:@[
|
|
599
|
+
@"resize", @"resizeAspect", @"resizeAspectFill", @"center", @"top", @"bottom",
|
|
600
|
+
@"left", @"right", @"topLeft", @"topRight", @"bottomLeft", @"bottomRight"
|
|
601
|
+
]];
|
|
602
|
+
return name && [known containsObject:name];
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// The constant for a gravity named as it looks, on the UI thread, where the
|
|
606
|
+
// layer can say whether its space is flipped.
|
|
607
|
+
static NSString* CALGravity(CALayer* L, NSString* name) {
|
|
608
|
+
bool flipped = L.contentsAreFlipped;
|
|
609
|
+
NSString* top = flipped ? kCAGravityBottom : kCAGravityTop;
|
|
610
|
+
NSString* bottom = flipped ? kCAGravityTop : kCAGravityBottom;
|
|
611
|
+
NSString* topLeft = flipped ? kCAGravityBottomLeft : kCAGravityTopLeft;
|
|
612
|
+
NSString* topRight = flipped ? kCAGravityBottomRight : kCAGravityTopRight;
|
|
613
|
+
NSString* bottomLeft = flipped ? kCAGravityTopLeft : kCAGravityBottomLeft;
|
|
614
|
+
NSString* bottomRight = flipped ? kCAGravityTopRight : kCAGravityBottomRight;
|
|
615
|
+
if ([name isEqualToString:@"top"]) return top;
|
|
616
|
+
if ([name isEqualToString:@"bottom"]) return bottom;
|
|
617
|
+
if ([name isEqualToString:@"topLeft"]) return topLeft;
|
|
618
|
+
if ([name isEqualToString:@"topRight"]) return topRight;
|
|
619
|
+
if ([name isEqualToString:@"bottomLeft"]) return bottomLeft;
|
|
620
|
+
if ([name isEqualToString:@"bottomRight"]) return bottomRight;
|
|
621
|
+
if ([name isEqualToString:@"left"]) return kCAGravityLeft;
|
|
622
|
+
if ([name isEqualToString:@"right"]) return kCAGravityRight;
|
|
623
|
+
if ([name isEqualToString:@"center"]) return kCAGravityCenter;
|
|
624
|
+
if ([name isEqualToString:@"resizeAspect"]) return kCAGravityResizeAspect;
|
|
625
|
+
if ([name isEqualToString:@"resizeAspectFill"]) return kCAGravityResizeAspectFill;
|
|
626
|
+
return kCAGravityResize;
|
|
627
|
+
}
|
|
628
|
+
|
|
588
629
|
static LayerPropsSpec ParseLayerProps(Napi::Object o) {
|
|
589
630
|
LayerPropsSpec s;
|
|
590
631
|
if (o.Has("frame")) {
|
|
@@ -648,6 +689,11 @@ static LayerPropsSpec ParseLayerProps(Napi::Object o) {
|
|
|
648
689
|
else s.transform = TransformFrom(tv);
|
|
649
690
|
}
|
|
650
691
|
if (o.Has("contents")) s.clearContents = o.Get("contents").IsNull();
|
|
692
|
+
if ((s.hasGravity = o.Has("contentsGravity"))) {
|
|
693
|
+
Napi::Value g = o.Get("contentsGravity");
|
|
694
|
+
s.gravity = g.IsString() ? ToNSString(g) : nil;
|
|
695
|
+
s.badGravity = !CALGravityKnown(s.gravity);
|
|
696
|
+
}
|
|
651
697
|
return s;
|
|
652
698
|
}
|
|
653
699
|
|
|
@@ -677,6 +723,7 @@ static void ApplyLayerProps(CALayer* L, const LayerPropsSpec& s) {
|
|
|
677
723
|
CALNoteContentsReplaced(L, nil);
|
|
678
724
|
L.contents = nil;
|
|
679
725
|
}
|
|
726
|
+
if (s.hasGravity) L.contentsGravity = CALGravity(L, s.gravity);
|
|
680
727
|
}
|
|
681
728
|
|
|
682
729
|
static Napi::Value SetLayerProps(const Napi::CallbackInfo& info) {
|
|
@@ -687,6 +734,14 @@ static Napi::Value SetLayerProps(const Napi::CallbackInfo& info) {
|
|
|
687
734
|
.ThrowAsJavaScriptException();
|
|
688
735
|
return info.Env().Undefined();
|
|
689
736
|
}
|
|
737
|
+
if (s.badGravity) {
|
|
738
|
+
Napi::TypeError::New(info.Env(),
|
|
739
|
+
"contentsGravity: resize, resizeAspect, resizeAspectFill, center, "
|
|
740
|
+
"top, bottom, left, right, topLeft, topRight, bottomLeft or "
|
|
741
|
+
"bottomRight")
|
|
742
|
+
.ThrowAsJavaScriptException();
|
|
743
|
+
return info.Env().Undefined();
|
|
744
|
+
}
|
|
690
745
|
CALOnLayers(^{
|
|
691
746
|
CALayer* L = CALResolve(target);
|
|
692
747
|
if (L) ApplyLayerProps(L, s);
|
|
@@ -1192,6 +1247,8 @@ static Napi::Value RemoveAllAnimations(const Napi::CallbackInfo& info) {
|
|
|
1192
1247
|
static Napi::Value JSFromCAValue(Napi::Env env, id v) {
|
|
1193
1248
|
if (!v) return env.Null();
|
|
1194
1249
|
if ([v isKindOfClass:[NSNumber class]]) return Napi::Number::New(env, [(NSNumber*)v doubleValue]);
|
|
1250
|
+
// a name — `contentsGravity` is Core Animation's own, in the layer's space
|
|
1251
|
+
if ([v isKindOfClass:[NSString class]]) return Napi::String::New(env, [(NSString*)v UTF8String]);
|
|
1195
1252
|
if ([v isKindOfClass:[NSValue class]]) {
|
|
1196
1253
|
NSValue* nv = (NSValue*)v;
|
|
1197
1254
|
const char* t = nv.objCType;
|
|
@@ -1261,8 +1318,8 @@ static Napi::Value PresentationValue(const Napi::CallbackInfo& info) {
|
|
|
1261
1318
|
v = nil;
|
|
1262
1319
|
}
|
|
1263
1320
|
}
|
|
1264
|
-
// an NSNumber, an NSValue or a
|
|
1265
|
-
// caller's thread
|
|
1321
|
+
// an NSNumber, an NSValue, a CGColor or a name: immutable, made into JS
|
|
1322
|
+
// on the caller's thread
|
|
1266
1323
|
return ^Napi::Value(Napi::Env e) { return JSFromCAValue(e, v); };
|
|
1267
1324
|
});
|
|
1268
1325
|
}
|