@windowkit/appkit 0.5.0 → 0.5.1
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 +12 -2
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/calayers.node +0 -0
- package/prebuilds/darwin-x64/calayers.node +0 -0
- package/src/addon.mm +22 -3
package/README.md
CHANGED
|
@@ -182,9 +182,19 @@ be additive; for that there is `presentationValue`.
|
|
|
182
182
|
value the render server is showing for that key path right now, animations applied: a
|
|
183
183
|
number, a point or size as `[x, y]`, a rect as `[x, y, w, h]`, a colour as `[r, g, b, a]`, a
|
|
184
184
|
transform as its sixteen components; `null` before the layer's first commit. A colour comes
|
|
185
|
-
back in
|
|
185
|
+
back in sRGB, the space it went in, so it can be handed straight back as a `from` —
|
|
186
186
|
but CA interpolates in the display's space, so the components' midpoint there is not this
|
|
187
|
-
space's midpoint.
|
|
187
|
+
space's midpoint.
|
|
188
|
+
|
|
189
|
+
**`native.colorSpace()`** — `'sRGB'`: the space every colour crossing this bridge is in —
|
|
190
|
+
a layer's `backgroundColor`, `borderColor` and `shadowColor`, a shape's fill and stroke,
|
|
191
|
+
a gradient's stops, an animation's `from`/`to`, a presentation value, a text span's ink
|
|
192
|
+
and the surfaces `createSurface` makes. One space, so a colour set on a layer and the
|
|
193
|
+
same colour rastered into a surface composite to the same pixels. (Before 0.6 the layer
|
|
194
|
+
half was Generic RGB, which the compositor converts on its way to the display: `#dbe7f4`
|
|
195
|
+
on a layer showed as (228, 236, 245) beside a surface's (219, 231, 244), and a colour
|
|
196
|
+
animation landed on a model value that did not match its own `to`. A caller that draws
|
|
197
|
+
both ways — react-x11's layer promotion — feature-detects the verb.) `speed: 0, timeOffset: t` plus a read is how a curve is sampled without
|
|
188
198
|
waiting for it, which is how `test/animation.js` checks every curve above.
|
|
189
199
|
|
|
190
200
|
**The end of an animation.** With an `id`, the animation's delegate forwards
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@windowkit/appkit",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
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",
|
|
Binary file
|
|
Binary file
|
package/src/addon.mm
CHANGED
|
@@ -44,13 +44,29 @@ static NSString* StrOr(Napi::Object o, const char* k, NSString* d) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
// [r,g,b] or [r,g,b,a], components 0..1 — caller owns the returned color.
|
|
47
|
+
//
|
|
48
|
+
// sRGB, like every other colour this bridge makes: the surfaces
|
|
49
|
+
// (createSurface, backend.mm), a text span's ink, an animation's from/to
|
|
50
|
+
// (BMakeColor). This one used to be Generic RGB, which the compositor
|
|
51
|
+
// converts on its way to the display, so a layer's backgroundColor came out
|
|
52
|
+
// paler than the same colour rastered into a surface — #dbe7f4 showed as
|
|
53
|
+
// (228, 236, 245) beside a bitmap's (219, 231, 244) — and a colour animation
|
|
54
|
+
// landed on a model value that did not match its own `to`. One space
|
|
55
|
+
// everywhere, and `colorSpace()` says so.
|
|
47
56
|
static CGColorRef MakeColor(Napi::Value v) {
|
|
48
57
|
Napi::Array a = v.As<Napi::Array>();
|
|
49
58
|
double r = a.Get(0u).As<Napi::Number>().DoubleValue();
|
|
50
59
|
double g = a.Get(1u).As<Napi::Number>().DoubleValue();
|
|
51
60
|
double b = a.Get(2u).As<Napi::Number>().DoubleValue();
|
|
52
61
|
double al = a.Length() > 3 ? a.Get(3u).As<Napi::Number>().DoubleValue() : 1.0;
|
|
53
|
-
return
|
|
62
|
+
return CGColorCreateSRGB(r, g, b, al);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// The colour space every colour crossing this bridge is in — layer
|
|
66
|
+
// properties, animation values, presentation values, surfaces. A caller
|
|
67
|
+
// that rasters in sRGB can feature-detect that a layer colour will match.
|
|
68
|
+
static Napi::Value ColorSpace(const Napi::CallbackInfo& info) {
|
|
69
|
+
return Napi::String::New(info.Env(), "sRGB");
|
|
54
70
|
}
|
|
55
71
|
|
|
56
72
|
static CGPoint PointFrom(Napi::Value v) {
|
|
@@ -863,7 +879,9 @@ static Napi::Value JSFromCAValue(Napi::Env env, id v) {
|
|
|
863
879
|
}
|
|
864
880
|
if (CFGetTypeID((__bridge CFTypeRef)v) == CGColorGetTypeID()) {
|
|
865
881
|
CGColorRef c = (__bridge CGColorRef)v;
|
|
866
|
-
|
|
882
|
+
// read back in the space colours go in by (MakeColor), so a value that
|
|
883
|
+
// went out comes back as the same numbers
|
|
884
|
+
CGColorSpaceRef rgb = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
|
|
867
885
|
CGColorRef conv = CGColorCreateCopyByMatchingToColorSpace(rgb, kCGRenderingIntentDefault, c, NULL);
|
|
868
886
|
CGColorSpaceRelease(rgb);
|
|
869
887
|
CGColorRef src = conv ? conv : c;
|
|
@@ -960,7 +978,7 @@ static NSAttributedString* AttrString(Napi::Object o, CGColorRef* outColor) {
|
|
|
960
978
|
NSString* fontName = StrOr(o, "fontName", @"Helvetica");
|
|
961
979
|
double fontSize = NumOr(o, "fontSize", 14);
|
|
962
980
|
CGColorRef color = o.Has("color") ? MakeColor(o.Get("color"))
|
|
963
|
-
:
|
|
981
|
+
: CGColorCreateSRGB(0, 0, 0, 1);
|
|
964
982
|
CTFontRef font = CTFontCreateWithName((__bridge CFStringRef)fontName, fontSize, NULL);
|
|
965
983
|
NSDictionary* attrs = @{
|
|
966
984
|
(__bridge id)kCTFontAttributeName : (__bridge id)font,
|
|
@@ -1295,6 +1313,7 @@ static Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
|
1295
1313
|
FN("txBegin", TxBegin);
|
|
1296
1314
|
FN("txCommit", TxCommit);
|
|
1297
1315
|
FN("presentationValue", PresentationValue);
|
|
1316
|
+
FN("colorSpace", ColorSpace);
|
|
1298
1317
|
FN("hitTest", HitTest);
|
|
1299
1318
|
FN("measureText", MeasureText);
|
|
1300
1319
|
FN("createTextImage", CreateTextImage);
|