dsh-task-cat 1.0.2 → 1.0.3

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/client.js CHANGED
@@ -37,15 +37,27 @@ window.__ModuleLoader__.load({
37
37
  * @returns true for a light surface, false for dark, null when unknowable.
38
38
  */
39
39
  function surfaceIsLight() {
40
- try {
41
- const background = getComputedStyle(document.body).backgroundColor;
42
- const match = /rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/.exec(background);
40
+ const read = (element) => {
41
+ if (element === null || element === undefined) return null;
42
+ const color = getComputedStyle(element).backgroundColor;
43
+ const match = /rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/.exec(color);
43
44
  if (match === null) return null;
44
45
  const alpha = match[4] === undefined ? 1 : Number(match[4]);
45
- // A transparent body says nothing about the surface underneath.
46
+ // A transparent element says nothing about the surface underneath.
46
47
  if (alpha < 0.2) return null;
47
48
  const luminance = (0.2126 * Number(match[1]) + 0.7152 * Number(match[2]) + 0.0722 * Number(match[3])) / 255;
48
49
  return luminance > 0.55;
50
+ };
51
+ try {
52
+ for (const element of [document.body, document.documentElement]) {
53
+ const light = read(element);
54
+ if (light !== null) return light;
55
+ }
56
+ // Last resort: the app follows the system unless the user overrode it,
57
+ // and a wrong answer is worse than the system's own opinion.
58
+ return typeof window.matchMedia === 'function'
59
+ ? !window.matchMedia('(prefers-color-scheme: dark)').matches
60
+ : null;
49
61
  } catch {
50
62
  return null;
51
63
  }
@@ -719,12 +719,35 @@ final class RosterFooterView: NSView {
719
719
  .font: NSFont.systemFont(ofSize: 11),
720
720
  .foregroundColor: NSColor.secondaryLabelColor,
721
721
  ]
722
+ effectiveAppearance.performAsCurrentDrawingAppearance {
723
+ // draw below uses the attributes above
724
+ }
722
725
  let size = (label as NSString).size(withAttributes: attrs)
723
726
  let point = NSPoint(x: (bounds.width - size.width) / 2, y: (bounds.height - size.height) / 2)
724
727
  (label as NSString).draw(at: point, withAttributes: attrs)
725
728
  }
726
729
  }
727
730
 
731
+ /// A card surface with an opaque fill chosen from the resolved appearance, so
732
+ /// the card looks the same over any desktop behind it.
733
+ final class CardView: NSView {
734
+ override var isOpaque: Bool { false }
735
+
736
+ override func draw(_ dirtyRect: NSRect) {
737
+ let dark = effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]) == .darkAqua
738
+ let fill = dark
739
+ ? NSColor(srgbRed: 0.145, green: 0.149, blue: 0.165, alpha: 0.985)
740
+ : NSColor(srgbRed: 0.992, green: 0.994, blue: 0.996, alpha: 0.985)
741
+ fill.setFill()
742
+ NSBezierPath(roundedRect: bounds, xRadius: 16, yRadius: 16).fill()
743
+ // A hairline keeps the edge visible when the card sits on a similar shade.
744
+ (dark ? NSColor.white.withAlphaComponent(0.10) : NSColor.black.withAlphaComponent(0.10)).setStroke()
745
+ let edge = NSBezierPath(roundedRect: bounds.insetBy(dx: 0.5, dy: 0.5), xRadius: 16, yRadius: 16)
746
+ edge.lineWidth = 1
747
+ edge.stroke()
748
+ }
749
+ }
750
+
728
751
  final class RosterPanel: NSPanel {
729
752
  /// Like the pet itself, the card never becomes key: the pet receives clicks
730
753
  /// reliably precisely because it never takes focus, and the card must behave
@@ -737,7 +760,7 @@ final class RosterPanel: NSPanel {
737
760
  /// Owns the roster panel: layout, scrolling, hover, click, dismissal.
738
761
  final class RosterController: NSObject {
739
762
  private let panel: RosterPanel
740
- private let card = NSVisualEffectView()
763
+ private let card = CardView()
741
764
  private let scroll = NSScrollView()
742
765
  private let document = FlippedView()
743
766
  private let head = NSView()
@@ -778,9 +801,6 @@ final class RosterController: NSObject {
778
801
  panel.isReleasedWhenClosed = false
779
802
  panel.collectionBehavior = [.canJoinAllSpaces, .stationary, .fullScreenAuxiliary]
780
803
 
781
- card.material = .popover
782
- card.blendingMode = .behindWindow
783
- card.state = .active
784
804
  card.wantsLayer = true
785
805
  card.layer?.cornerRadius = 16
786
806
  card.layer?.masksToBounds = true
@@ -919,19 +939,26 @@ final class RosterController: NSObject {
919
939
  height: max(40, height - headHeight - Self.padding * 1.5))
920
940
 
921
941
  document.frame = NSRect(x: 0, y: 0, width: Self.width - Self.padding * 2 - 2, height: listHeight)
922
- var cursor = listHeight - Self.padding
942
+ var cursor = CGFloat(2)
923
943
  for row in rows {
924
- cursor -= row.frame.height
925
944
  row.frame.origin = NSPoint(x: 0, y: cursor)
926
945
  document.addSubview(row)
946
+ cursor += row.frame.height
927
947
  }
928
948
  if let footer {
929
- cursor -= footer.frame.height
930
949
  footer.frame.origin = NSPoint(x: 0, y: cursor)
931
950
  document.addSubview(footer)
932
951
  }
933
952
  scroll.documentView?.scroll(NSPoint(x: 0, y: 0))
934
953
 
954
+ // Colours resolve against the effective appearance; anything created before
955
+ // it settled must repaint or it stays invisible.
956
+ for piece in rows + [document, scroll] {
957
+ piece.needsDisplay = true
958
+ }
959
+ footer?.needsDisplay = true
960
+ head.needsDisplay = true
961
+
935
962
  panel.orderFrontRegardless()
936
963
  startHoverWatch(petFrame: petFrame)
937
964
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-task-cat",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Task cat: a floating white cat that watches every session's progress and jumps into the conversation that needs you.",
5
5
  "type": "module",
6
6
  "exports": {