dsh-native-uia 0.2.0 → 0.6.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.
Files changed (55) hide show
  1. package/README.md +81 -398
  2. package/client/client.js +236 -48
  3. package/cordis.patch.yml +7 -8
  4. package/locale/en.json +2 -2
  5. package/locale/zh.json +2 -2
  6. package/package.json +8 -17
  7. package/scripts/check-lease.mjs +1 -1
  8. package/scripts/lib/dsh-tools-stub.mjs +14 -0
  9. package/scripts/lib/load-tools-source.mjs +17 -16
  10. package/scripts/lib/sources.mjs +62 -0
  11. package/scripts/load-tools.mjs +74 -0
  12. package/scripts/measure-parse.mjs +2 -2
  13. package/scripts/regression-tools.mjs +155 -6
  14. package/scripts/regression-worker.ps1 +29 -0
  15. package/scripts/verify-live-style.mjs +46 -0
  16. package/scripts/verify-live.mjs +12 -18
  17. package/scripts/verify.mjs +953 -192
  18. package/src/activity-window.js +71 -7
  19. package/src/dashboard.js +27 -69
  20. package/src/guard.js +39 -10
  21. package/src/index.js +187 -77
  22. package/src/notes.js +83 -0
  23. package/src/state.js +97 -10
  24. package/src/themes.js +66 -0
  25. package/src/tools/defs/act.js +671 -0
  26. package/src/tools/defs/lifecycle.js +205 -0
  27. package/src/tools/defs/observe.js +325 -0
  28. package/src/tools/defs/pointer.js +328 -0
  29. package/src/tools/format.js +338 -0
  30. package/src/tools/index.js +125 -0
  31. package/src/tools/ocr.js +91 -0
  32. package/src/tools/recipes.js +49 -0
  33. package/src/tools/runtime.js +42 -0
  34. package/src/worker-client.js +32 -10
  35. package/worker/assets/dsh-whale.path +1 -0
  36. package/worker/indicator-server.ps1 +1107 -72
  37. package/worker/lib/01-core.ps1 +64 -0
  38. package/worker/lib/02-uia.ps1 +224 -0
  39. package/worker/lib/03-window.ps1 +194 -0
  40. package/worker/lib/04-match.ps1 +435 -0
  41. package/worker/lib/05-value.ps1 +254 -0
  42. package/worker/lib/06-snapshot.ps1 +412 -0
  43. package/worker/lib/07-action.ps1 +329 -0
  44. package/worker/lib/08-command.ps1 +1495 -0
  45. package/worker/lib/09-pointer.ps1 +840 -0
  46. package/worker/lib/10-dispatch.ps1 +132 -0
  47. package/worker/ps-stdio.ps1 +7 -2
  48. package/worker/uia-worker.ps1 +599 -4220
  49. package/locale/desktop/en.json +0 -6
  50. package/locale/desktop/zh.json +0 -6
  51. package/scripts/regression-halt-latch.mjs +0 -100
  52. package/src/native-uia-remote.js +0 -80
  53. package/src/panel-face.js +0 -14
  54. package/src/tools.js +0 -1482
  55. package/web/control.html +0 -1413
@@ -57,7 +57,7 @@ function EnvInt($name, $default) {
57
57
  return $n
58
58
  }
59
59
  $CFG = [ordered]@{
60
- renderMs = EnvInt 'DSH_INDICATOR_RENDER_MS' 100 # visual update interval of the pulse (ms)
60
+ renderMs = EnvInt 'DSH_INDICATOR_RENDER_MS' 33 # visual update interval of the pulse (ms)
61
61
  pulseMs = EnvInt 'DSH_INDICATOR_PULSE_MS' 2400 # acting pulse period
62
62
  idleMs = EnvInt 'DSH_INDICATOR_IDLE_MS' 120000 # default auto-hide after silence
63
63
  ringPx = EnvInt 'DSH_INDICATOR_RING_PX' 26 # ring thickness in PHYSICAL pixels
@@ -371,13 +371,15 @@ if ($script:wpfAssemblies) {
371
371
  # ---------------------------------------------------------------- non-ASCII text, by code point
372
372
  function CU([int[]]$codes) { $s = ''; foreach ($c in $codes) { $s = $s + [string][char]$c }; return $s }
373
373
  $script:TEXT = [ordered]@{
374
- brand = CU @(0x5FA1, 0x5C4F) # "Yu ping"
374
+ brand = CU @(0x44, 0x53, 0x48) # "DSH" — the host's name, not the plugin's
375
375
  dot = CU @(0x00B7) # middle dot
376
- acting = CU @(0x6B63, 0x5728, 0x64CD, 0x63A7) # "currently controlling"
376
+ acting = CU @(0x6B63, 0x5728, 0x64CD, 0x63A7, 0x7535, 0x8111) # "currently controlling the computer"
377
377
  stopped = CU @(0x5DF2, 0x505C, 0x6B62) # "stopped"
378
378
  }
379
379
  # Every visible phase carries the brand: the label identifies WHO is on the screen, so a phase
380
- # change must recolour and reword the state without dropping the 御屏 name itself.
380
+ # change must recolour and reword the state without dropping the name itself. The brand is the
381
+ # host (DSH), because the person at the keyboard is sharing their desktop with the harness, not
382
+ # with a plugin — 御屏 is what this thing is called in the plugin list, not what is on their screen.
381
383
  # There are two visible phases, not three: a paused state was removed from the product, so the
382
384
  # capsule only ever says "acting" or (briefly, on the way out) "stopped".
383
385
  $script:PILL = @{
@@ -394,9 +396,10 @@ function ColA([double]$a, $rgb) {
394
396
  return [System.Windows.Media.Color]::FromArgb([byte]$al, [byte]$rgb[0], [byte]$rgb[1], [byte]$rgb[2])
395
397
  }
396
398
  $script:PH = @{
397
- acting = @{ periodMs = [int]$CFG.pulseMs; lo = 0.55; hi = 1.00; base = @(205, 188, 243); g0 = @(217, 204, 247); g1 = @(192, 168, 238) }
399
+ acting = @{ periodMs = [int]$CFG.pulseMs; lo = 0.68; hi = 1.00; base = @(169, 180, 196); g0 = @(230, 235, 242); g1 = @(147, 161, 181) }
400
+ # stopped stays warm red on purpose: silver means "machine is driving", red means "it let go".
398
401
  stopped = @{ periodMs = 900; lo = 0.72; hi = 1.00; base = @(255, 91, 93); g0 = @(255, 93, 93); g1 = @(232, 54, 93) }
399
- hidden = @{ periodMs = [int]$CFG.pulseMs; lo = 0.55; hi = 1.00; base = @(205, 188, 243); g0 = @(217, 204, 247); g1 = @(192, 168, 238) }
402
+ hidden = @{ periodMs = [int]$CFG.pulseMs; lo = 0.55; hi = 1.00; base = @(169, 180, 196); g0 = @(230, 235, 242); g1 = @(147, 161, 181) }
400
403
  }
401
404
 
402
405
  # ---------------------------------------------------------------- plugin-supplied palette
@@ -484,6 +487,25 @@ $script:S = [ordered]@{
484
487
  pill = $null
485
488
  pillText = $null
486
489
  pillSub = $null
490
+ pillOrb = $null
491
+ pillOrbScale = $null
492
+ pillOrbHalo = $null
493
+ pillOrbHaloScale = $null
494
+ pillBars = @()
495
+ pillStyle = 'orb'
496
+ # Whether the thin smoke at the lip is drawn. Decoration only, so it is the person's switch; it
497
+ # is part of the look, which is why it joins the layout key rather than being applied in place.
498
+ mistOn = $true
499
+ lookVersion = 0
500
+ # How many times the visual tree has been thrown away (each one replays the intro animation).
501
+ layoutBuilds = 0
502
+ # The palette signature last baked into the tree. The plugin re-sends the palette on every command,
503
+ # so this is what distinguishes "same colours again" from "the person changed the theme".
504
+ paletteSig = ''
505
+ layoutKey = ''
506
+ pillScale = $null
507
+ pillBrandRun = $null
508
+ pillRestRun = $null
487
509
  built = $false
488
510
  visible = $false
489
511
  hwnd = [Int64]0
@@ -801,19 +823,65 @@ function New-GradH($rgb0, $rgb1, [double]$a, [bool]$flip) {
801
823
  return $b
802
824
  }
803
825
 
826
+ function Test-DarkAmbient($rgb) {
827
+ # A ramp whose average luminance is below mid-grey is an ambient that DARKENS the screen instead
828
+ # of lighting it. The two need opposite geometry (see New-Vignette), so the distinction has to be
829
+ # made from the palette, not hardcoded per theme id.
830
+ if ($null -eq $rgb -or $rgb.Count -lt 3) { return $false }
831
+ $l = 0.299 * [double]$rgb[0] + 0.587 * [double]$rgb[1] + 0.114 * $rgb[2]
832
+ return ($l -lt 96.0)
833
+ }
834
+
804
835
  function New-Fade([double]$sx, [double]$sy, [double]$ex, [double]$ey, [double]$strength) {
805
836
  # opacity mask: solid at the monitor edge, fading inward
806
837
  $b = New-Object System.Windows.Media.LinearGradientBrush
807
838
  $b.StartPoint = New-Object System.Windows.Point -ArgumentList $sx, $sy
808
839
  $b.EndPoint = New-Object System.Windows.Point -ArgumentList $ex, $ey
809
840
  $a255 = [int][Math]::Round([Math]::Min(1.0, $strength) * 255.0)
810
- $p0 = New-Object System.Windows.Media.GradientStop
811
- $p0.Color = [System.Windows.Media.Color]::FromArgb([byte]$a255, 255, 255, 255); $p0.Offset = 0.0
812
- $p1 = New-Object System.Windows.Media.GradientStop
813
- $p1.Color = [System.Windows.Media.Color]::FromArgb([byte]($a255 * 0.40), 255, 255, 255); $p1.Offset = 0.42
814
- $p2 = New-Object System.Windows.Media.GradientStop
815
- $p2.Color = [System.Windows.Media.Color]::FromArgb([byte]0, 255, 255, 255); $p2.Offset = 1.0
816
- foreach ($p in @($p0, $p1, $p2)) { [void]$b.GradientStops.Add($p) }
841
+ # One continuous falloff: no mid-stop shelf, no second hard edge. The old 0.42 shelf plus the
842
+ # separate solid ring bar is what read as two stacked bands around the screen.
843
+ foreach ($p in @(
844
+ @{ o = 0.00; a = $a255 },
845
+ @{ o = 0.16; a = [int]($a255 * 0.86) },
846
+ @{ o = 0.36; a = [int]($a255 * 0.58) },
847
+ @{ o = 0.58; a = [int]($a255 * 0.30) },
848
+ @{ o = 0.78; a = [int]($a255 * 0.10) },
849
+ @{ o = 1.00; a = 0 }
850
+ )) {
851
+ $gs = New-Object System.Windows.Media.GradientStop
852
+ $gs.Color = [System.Windows.Media.Color]::FromArgb([byte]$p.a, 255, 255, 255)
853
+ $gs.Offset = [double]$p.o
854
+ [void]$b.GradientStops.Add($gs)
855
+ }
856
+ [void]$b.Freeze()
857
+ return $b
858
+ }
859
+
860
+ function New-Vignette([double]$sx, [double]$sy, [double]$ex, [double]$ey, [double]$strength) {
861
+ # The mask for a DARK ambient. A black rim drawn with New-Fade's profile is densest at the screen
862
+ # edge and dissolves inward, which on a dark desktop reads as "the screen is a bit dim at the
863
+ # border" -- measured at luminance 4..21 against a desktop edge of 75, i.e. it merged into the
864
+ # wallpaper and was invisible as a deliberate effect. A vignette has the opposite profile: it
865
+ # ramps UP over the first part of the band, holds at full density through the middle, and then
866
+ # releases -- so the darkest part sits just inside the edge, where the eye reads it as a frame
867
+ # rather than as missing pixels. That is what makes a black ambient look intentional.
868
+ $b = New-Object System.Windows.Media.LinearGradientBrush
869
+ $b.StartPoint = New-Object System.Windows.Point -ArgumentList $sx, $sy
870
+ $b.EndPoint = New-Object System.Windows.Point -ArgumentList $ex, $ey
871
+ $a255 = [int][Math]::Round([Math]::Min(1.0, $strength) * 255.0)
872
+ foreach ($p in @(
873
+ @{ o = 0.00; a = [int]($a255 * 0.55) },
874
+ @{ o = 0.18; a = $a255 },
875
+ @{ o = 0.46; a = $a255 },
876
+ @{ o = 0.70; a = [int]($a255 * 0.72) },
877
+ @{ o = 0.88; a = [int]($a255 * 0.28) },
878
+ @{ o = 1.00; a = 0 }
879
+ )) {
880
+ $gs = New-Object System.Windows.Media.GradientStop
881
+ $gs.Color = [System.Windows.Media.Color]::FromArgb([byte]$p.a, 255, 255, 255)
882
+ $gs.Offset = [double]$p.o
883
+ [void]$b.GradientStops.Add($gs)
884
+ }
817
885
  [void]$b.Freeze()
818
886
  return $b
819
887
  }
@@ -840,26 +908,26 @@ function New-Bar([double]$x, [double]$y, [double]$w, [double]$h, $fill, $mask) {
840
908
  function Build-Ring([double]$W, [double]$H, [double]$T, $ph) {
841
909
  $bars = New-Object System.Collections.Generic.List[object]
842
910
  $bloom = New-Object System.Collections.Generic.List[object]
843
- $a = 0.90
844
- [void]$bars.Add((New-Bar 0 0 $W $T (New-GradH $ph.g0 $ph.g1 $a $false) (New-Fade 0.5 0.0 0.5 1.0 1.0)))
845
- [void]$bars.Add((New-Bar 0 ($H - $T) $W $T (New-GradH $ph.g0 $ph.g1 $a $true) (New-Fade 0.5 1.0 0.5 0.0 1.0)))
846
- [void]$bars.Add((New-Bar 0 0 $T $H (New-GradH $ph.g0 $ph.g1 $a $false) (New-Fade 0.0 0.5 1.0 0.5 1.0)))
847
- [void]$bars.Add((New-Bar ($W - $T) 0 $T $H (New-GradH $ph.g0 $ph.g1 $a $true) (New-Fade 1.0 0.5 0.0 0.5 1.0)))
848
- $bt = $T * 2.4
849
- [void]$bloom.Add((New-Bar 0 0 $W $bt (New-GradH $ph.g0 $ph.g1 0.30 $false) (New-Fade 0.5 0.0 0.5 1.0 1.0)))
850
- [void]$bloom.Add((New-Bar 0 ($H - $bt) $W $bt (New-GradH $ph.g0 $ph.g1 0.30 $true) (New-Fade 0.5 1.0 0.5 0.0 1.0)))
851
- [void]$bloom.Add((New-Bar 0 0 $bt $H (New-GradH $ph.g0 $ph.g1 0.30 $false) (New-Fade 0.0 0.5 1.0 0.5 1.0)))
852
- [void]$bloom.Add((New-Bar ($W - $bt) 0 $bt $H (New-GradH $ph.g0 $ph.g1 0.30 $true) (New-Fade 1.0 0.5 0.0 0.5 1.0)))
853
- $hair = New-Object System.Windows.Shapes.Rectangle
854
- $hair.Stroke = (New-Solid $ph.base 0.85)
855
- $hair.StrokeThickness = 1.0
856
- $hair.Fill = $null
857
- $hair.Width = [Math]::Max(1.0, $W - 1.0)
858
- $hair.Height = [Math]::Max(1.0, $H - 1.0)
859
- [System.Windows.Controls.Canvas]::SetLeft($hair, 0.5)
860
- [System.Windows.Controls.Canvas]::SetTop($hair, 0.5)
861
- $hair.IsHitTestVisible = $false
862
- return @{ bars = $bars; bloom = $bloom; hair = $hair }
911
+ # One wide falloff layer per edge, no separate hard ring bar: the edge light is a single soft
912
+ # gradient that dissolves inward, so there are no stacked bands.
913
+ #
914
+ # The ramp is g0 -> g1, i.e. the palette's ringFrom -> ringTo. It used to be base -> base, and
915
+ # `base` is pillBorder -- which BOTH palettes carry identically. That is why choosing an ambient
916
+ # moved the stored value and not one pixel of the ring: the theme only ever reached the capsule.
917
+ #
918
+ # The MASK depends on whether the ambient lightens or darkens. A light ramp with the edge-dense
919
+ # falloff looks like light bleeding in from the frame; a dark ramp with the same profile just looks
920
+ # like a slightly dimmer border that merges into the wallpaper (measured: luminance 4..21 against a
921
+ # desktop edge of 75 -- present, and invisible as an effect). A dark ambient gets the vignette
922
+ # profile instead, which puts its darkest band just inside the edge so the eye reads a frame.
923
+ $dark = Test-DarkAmbient $ph.g0
924
+ $E = $T * 4.0
925
+ $mask = if ($dark) { 'New-Vignette' } else { 'New-Fade' }
926
+ [void]$bloom.Add((New-Bar 0 0 $W $E (New-GradH $ph.g0 $ph.g1 0.85 $false) (& $mask 0.5 0.0 0.5 1.0 1.0)))
927
+ [void]$bloom.Add((New-Bar 0 ($H - $E) $W $E (New-GradH $ph.g1 $ph.g0 0.85 $false) (& $mask 0.5 1.0 0.5 0.0 1.0)))
928
+ [void]$bloom.Add((New-Bar 0 0 $E $H (New-GradH $ph.g0 $ph.g1 0.85 $true) (& $mask 0.0 0.5 1.0 0.5 1.0)))
929
+ [void]$bloom.Add((New-Bar ($W - $E) 0 $E $H (New-GradH $ph.g0 $ph.g1 0.85 $false) (& $mask 1.0 0.5 0.0 0.5 1.0)))
930
+ return @{ bars = $bars; bloom = $bloom }
863
931
  }
864
932
 
865
933
  function New-CursorGlowSource($cd, $ph, $opacity) {
@@ -972,50 +1040,896 @@ function Position-Halo {
972
1040
  }
973
1041
  }
974
1042
 
1043
+ function Get-WhaleWagPoint([System.Windows.Point]$p, [double]$angle, [double]$thr, [double]$tip, [double]$px, [double]$py) {
1044
+ # Skinning weight along the body: zero at the peduncle, one at the fluke tip. The blend band is
1045
+ # narrow (2 units), so the fluke rotates as a near-rigid piece and keeps its own shape instead of
1046
+ # shearing into a blob; the outline stays one closed figure, so there is no seam and no joint.
1047
+ $t = ($p.X - $thr) / ($tip - $thr)
1048
+ if ($t -lt 0.0) { $t = 0.0 } elseif ($t -gt 1.0) { $t = 1.0 }
1049
+ $w = $t * $t * (3.0 - 2.0 * $t)
1050
+ if ($w -le 0.0001) { return $p }
1051
+ $rad = ($angle * $w) * [Math]::PI / 180.0
1052
+ $c = [Math]::Cos($rad); $s = [Math]::Sin($rad)
1053
+ $dx = $p.X - $px; $dy = $p.Y - $py
1054
+ return New-Object System.Windows.Point -ArgumentList ($px + $dx * $c - $dy * $s), ($py + $dx * $s + $dy * $c)
1055
+ }
1056
+
1057
+ function Add-WhaleWagAnimation($target, $dp, [System.Windows.Point]$p, [double]$swing, [double]$thr, [double]$tip, [double]$px, [double]$py, $ease) {
1058
+ $from = Get-WhaleWagPoint $p (-$swing) $thr $tip $px $py
1059
+ $to = Get-WhaleWagPoint $p $swing $thr $tip $px $py
1060
+ if ([Math]::Abs($from.X - $to.X) -lt 0.0005 -and [Math]::Abs($from.Y - $to.Y) -lt 0.0005) {
1061
+ $target.SetValue($dp, $p)
1062
+ return
1063
+ }
1064
+ $anim = New-Object System.Windows.Media.Animation.PointAnimation
1065
+ $anim.From = $from
1066
+ $anim.To = $to
1067
+ $anim.Duration = [TimeSpan]::FromMilliseconds(1200)
1068
+ [System.Windows.Media.Animation.Timeline]::SetDesiredFrameRate($anim, 30)
1069
+ $anim.AutoReverse = $true
1070
+ $anim.RepeatBehavior = [System.Windows.Media.Animation.RepeatBehavior]::Forever
1071
+ $anim.EasingFunction = $ease
1072
+ $target.BeginAnimation($dp, $anim)
1073
+ }
1074
+
1075
+ function Get-WhaleWagEnvelope([System.Windows.Media.PathGeometry]$source, [double]$swing) {
1076
+ # The union of the silhouette over the whole swing, as a Rect. This is what the measured bounds
1077
+ # have to be pinned to: a frame drawn from the REST bounds only fixes the left side, while the
1078
+ # fluke travels outward by up to ~3.5 DIP, so DesiredSize still changed every frame and the
1079
+ # element was re-arranged anyway. Sampling the swing (both extremes, plus zero) and taking the
1080
+ # union makes the measured size constant for every angle in between.
1081
+ $thr = 161.0; $tip = 165.0; $px = 163.8; $py = 20.6
1082
+ $x0 = [double]::MaxValue; $y0 = [double]::MaxValue
1083
+ $x1 = [double]::MinValue; $y1 = [double]::MinValue
1084
+ foreach ($angle in @((-1.0 * $swing), 0.0, (1.0 * $swing))) {
1085
+ $g = New-Object System.Windows.Media.PathGeometry
1086
+ $g.FillRule = $source.FillRule
1087
+ foreach ($f in $source.Figures) {
1088
+ $nf = New-Object System.Windows.Media.PathFigure
1089
+ $nf.StartPoint = (Get-WhaleWagPoint $f.StartPoint $angle $thr $tip $px $py)
1090
+ $nf.IsClosed = $f.IsClosed
1091
+ $nf.IsFilled = $f.IsFilled
1092
+ foreach ($seg in $f.Segments) {
1093
+ if ($seg -is [System.Windows.Media.PolyBezierSegment]) {
1094
+ $pts = $seg.Points
1095
+ for ($i = 0; $i + 2 -lt $pts.Count; $i += 3) {
1096
+ [void]$nf.Segments.Add((New-Object System.Windows.Media.BezierSegment -ArgumentList `
1097
+ (Get-WhaleWagPoint $pts[$i] $angle $thr $tip $px $py), `
1098
+ (Get-WhaleWagPoint $pts[$i + 1] $angle $thr $tip $px $py), `
1099
+ (Get-WhaleWagPoint $pts[$i + 2] $angle $thr $tip $px $py), $true))
1100
+ }
1101
+ } elseif ($seg -is [System.Windows.Media.PolyLineSegment]) {
1102
+ foreach ($pt in $seg.Points) {
1103
+ [void]$nf.Segments.Add((New-Object System.Windows.Media.LineSegment -ArgumentList (Get-WhaleWagPoint $pt $angle $thr $tip $px $py), $true))
1104
+ }
1105
+ } elseif ($seg -is [System.Windows.Media.BezierSegment]) {
1106
+ [void]$nf.Segments.Add((New-Object System.Windows.Media.BezierSegment -ArgumentList `
1107
+ (Get-WhaleWagPoint $seg.Point1 $angle $thr $tip $px $py), `
1108
+ (Get-WhaleWagPoint $seg.Point2 $angle $thr $tip $px $py), `
1109
+ (Get-WhaleWagPoint $seg.Point3 $angle $thr $tip $px $py), $true))
1110
+ } else {
1111
+ [void]$nf.Segments.Add($seg.Clone())
1112
+ }
1113
+ }
1114
+ [void]$g.Figures.Add($nf)
1115
+ }
1116
+ $b = $g.Bounds
1117
+ if ($b.X -lt $x0) { $x0 = $b.X }
1118
+ if ($b.Y -lt $y0) { $y0 = $b.Y }
1119
+ if (($b.X + $b.Width) -gt $x1) { $x1 = $b.X + $b.Width }
1120
+ if (($b.Y + $b.Height) -gt $y1) { $y1 = $b.Y + $b.Height }
1121
+ }
1122
+ return New-Object System.Windows.Rect -ArgumentList $x0, $y0, ($x1 - $x0), ($y1 - $y0)
1123
+ }
1124
+
1125
+ function New-WhaleWagGeometry([System.Windows.Media.PathGeometry]$source, [double]$swing) {
1126
+ # WPF has no SMIL, so the same idea is applied to the vector itself: every Bezier control point in
1127
+ # the tail gets a weighted PointAnimation. One closed figure stays one closed figure throughout.
1128
+ $thr = 161.0; $tip = 165.0; $px = 163.8; $py = 20.6
1129
+ $ease = New-Object System.Windows.Media.Animation.SineEase
1130
+ $ease.EasingMode = [System.Windows.Media.Animation.EasingMode]::EaseInOut
1131
+ $pg = New-Object System.Windows.Media.PathGeometry
1132
+ $pg.FillRule = $source.FillRule
1133
+ foreach ($f in $source.Figures) {
1134
+ $nf = New-Object System.Windows.Media.PathFigure
1135
+ $nf.StartPoint = $f.StartPoint
1136
+ $nf.IsClosed = $f.IsClosed
1137
+ $nf.IsFilled = $f.IsFilled
1138
+ Add-WhaleWagAnimation $nf ([System.Windows.Media.PathFigure]::StartPointProperty) $f.StartPoint $swing $thr $tip $px $py $ease
1139
+ foreach ($seg in $f.Segments) {
1140
+ if ($seg -is [System.Windows.Media.PolyBezierSegment]) {
1141
+ $pts = $seg.Points
1142
+ for ($i = 0; $i + 2 -lt $pts.Count; $i += 3) {
1143
+ $bs = New-Object System.Windows.Media.BezierSegment -ArgumentList $pts[$i], $pts[$i + 1], $pts[$i + 2], $true
1144
+ Add-WhaleWagAnimation $bs ([System.Windows.Media.BezierSegment]::Point1Property) $pts[$i] $swing $thr $tip $px $py $ease
1145
+ Add-WhaleWagAnimation $bs ([System.Windows.Media.BezierSegment]::Point2Property) $pts[$i + 1] $swing $thr $tip $px $py $ease
1146
+ Add-WhaleWagAnimation $bs ([System.Windows.Media.BezierSegment]::Point3Property) $pts[$i + 2] $swing $thr $tip $px $py $ease
1147
+ [void]$nf.Segments.Add($bs)
1148
+ }
1149
+ } elseif ($seg -is [System.Windows.Media.PolyLineSegment]) {
1150
+ foreach ($pt in $seg.Points) {
1151
+ $ls = New-Object System.Windows.Media.LineSegment -ArgumentList $pt, $true
1152
+ Add-WhaleWagAnimation $ls ([System.Windows.Media.LineSegment]::PointProperty) $pt $swing $thr $tip $px $py $ease
1153
+ [void]$nf.Segments.Add($ls)
1154
+ }
1155
+ } elseif ($seg -is [System.Windows.Media.BezierSegment]) {
1156
+ $bs = New-Object System.Windows.Media.BezierSegment -ArgumentList $seg.Point1, $seg.Point2, $seg.Point3, $true
1157
+ Add-WhaleWagAnimation $bs ([System.Windows.Media.BezierSegment]::Point1Property) $seg.Point1 $swing $thr $tip $px $py $ease
1158
+ Add-WhaleWagAnimation $bs ([System.Windows.Media.BezierSegment]::Point2Property) $seg.Point2 $swing $thr $tip $px $py $ease
1159
+ Add-WhaleWagAnimation $bs ([System.Windows.Media.BezierSegment]::Point3Property) $seg.Point3 $swing $thr $tip $px $py $ease
1160
+ [void]$nf.Segments.Add($bs)
1161
+ } else {
1162
+ [void]$nf.Segments.Add($seg.Clone())
1163
+ }
1164
+ }
1165
+ [void]$pg.Figures.Add($nf)
1166
+ }
1167
+ return $pg
1168
+ }
1169
+
1170
+ function New-WhaleShape([double]$slot, [double]$inset, $stops, [bool]$animate) {
1171
+ # One whale, two homes. The orb floats it on the dark shell and the paper capsule sets it inside
1172
+ # its chip; both must be the SAME vector, or the identity mark becomes two different drawings.
1173
+ # `slot` is the square the mark lives in, `inset` how much of it the silhouette may use.
1174
+ $canvas = New-Object System.Windows.Controls.Canvas
1175
+ $canvas.Width = $slot
1176
+ $canvas.Height = $slot
1177
+ $canvas.ClipToBounds = $false
1178
+ $pathFile = Join-Path $PSScriptRoot 'assets\dsh-whale.path'
1179
+ if (-not (Test-Path -LiteralPath $pathFile)) {
1180
+ Log 'whale path missing: worker\assets\dsh-whale.path'
1181
+ return $canvas
1182
+ }
1183
+ $d = (Get-Content -LiteralPath $pathFile -Raw).Trim()
1184
+ $source = [System.Windows.Media.PathGeometry]::CreateFromGeometry([System.Windows.Media.Geometry]::Parse($d))
1185
+ $shape = New-Object System.Windows.Shapes.Path
1186
+ $b = $source.Bounds
1187
+ # The measured size is what makes the icon shake, so it is removed from the picture entirely.
1188
+ #
1189
+ # A Path with Stretch=None reports DesiredSize from its geometry's bounds. When that geometry is
1190
+ # animated, the bounds move with the animation: measured across the swing the scaled right edge
1191
+ # travels 3.47 DIP (5.2 physical px at 1.5x). WPF then re-arranges the element every frame, and
1192
+ # because the arrange offset is derived from the size, the DRAWN ORIGIN moves too -- the whole
1193
+ # silhouette shifts a pixel while the tail barely moves. A filmstrip showed it plainly: most
1194
+ # frames identical, then one frame where the entire outline changed at once.
1195
+ #
1196
+ # An invisible "frame" figure pinned to the swing's union does NOT fix this: WPF computes Bounds
1197
+ # from the geometry's BASE value, so the frame pins the base and the animated points still move
1198
+ # the live bounds. Verified in the bench.
1199
+ #
1200
+ # So the element gets an explicit, constant Width/Height and Stretch=Fill: layout measures the
1201
+ # constant, and the geometry is mapped into that box by the stretch instead of by its own size.
1202
+ # The transform then only has to place the box, and it is built from the same union so no angle
1203
+ # can ever push the fluke outside it.
1204
+ $env = if ($animate) { Get-WhaleWagEnvelope $source 20.0 } else { $b }
1205
+ $slotW = $env.Width
1206
+ $slotH = $env.Height
1207
+ $shape.Width = $slotW
1208
+ $shape.Height = $slotH
1209
+ $shape.Stretch = [System.Windows.Media.Stretch]::Fill
1210
+ $shape.IsHitTestVisible = $false
1211
+ $shape.HorizontalAlignment = [System.Windows.HorizontalAlignment]::Left
1212
+ $shape.VerticalAlignment = [System.Windows.VerticalAlignment]::Top
1213
+ if ($animate) {
1214
+ $shape.Data = New-WhaleWagGeometry $source 20.0
1215
+ } else {
1216
+ $shape.Data = $source
1217
+ }
1218
+ # Place the constant box in the slot, centred, at the requested inset.
1219
+ $fit = $inset / [Math]::Max($env.Width, $env.Height)
1220
+ $tx = ($slot - $slotW * $fit) / 2.0
1221
+ $ty = ($slot - $slotH * $fit) / 2.0
1222
+ $shape.RenderTransform = New-Object System.Windows.Media.MatrixTransform -ArgumentList $fit, 0.0, 0.0, $fit, $tx, $ty
1223
+ $brush = New-Object System.Windows.Media.LinearGradientBrush
1224
+ $brush.MappingMode = [System.Windows.Media.BrushMappingMode]::Absolute
1225
+ $brush.StartPoint = New-Object System.Windows.Point -ArgumentList $b.X, $b.Y
1226
+ $brush.EndPoint = New-Object System.Windows.Point -ArgumentList ($b.X + $b.Width), ($b.Y + $b.Height)
1227
+ foreach ($s in $stops) {
1228
+ $gs = New-Object System.Windows.Media.GradientStop
1229
+ $gs.Color = [System.Windows.Media.Color]::FromArgb([byte]$s.c[0], [byte]$s.c[1], [byte]$s.c[2], [byte]$s.c[3])
1230
+ $gs.Offset = [double]$s.o
1231
+ [void]$brush.GradientStops.Add($gs)
1232
+ }
1233
+ $shape.Fill = $brush
1234
+ [void]$canvas.Children.Add($shape)
1235
+ return $canvas
1236
+ }
1237
+
1238
+ function New-PillOrb($ph, [bool]$inverse) {
1239
+ # The identity mark is the DSH whale itself, cut out of the shell: no glass bead, no specular dot,
1240
+ # no painted rim, and -- on either shell -- no chip behind it. The vector path is the same one the
1241
+ # host uses in its welcome wordmark; it is scaled into an 18 DIP slot so the silhouette stays
1242
+ # crisp at any DPI.
1243
+ #
1244
+ # The paper capsule used to wrap this in a 20 DIP rounded chip so a white whale had something to
1245
+ # sit on. That chip was the "why does the white capsule's whale have its own background" problem:
1246
+ # the mark carried a second surface the black capsule never had, and the two shapes no longer read
1247
+ # as the same object. The whale is drawn straight onto the shell instead, in ink for paper.
1248
+ $wrap = New-Object System.Windows.Controls.Grid
1249
+ $wrap.Width = 18; $wrap.Height = 18
1250
+ $wrap.VerticalAlignment = [System.Windows.VerticalAlignment]::Center
1251
+ $scale = New-Object System.Windows.Media.ScaleTransform -ArgumentList 1.0, 1.0
1252
+ $wrap.RenderTransform = $scale
1253
+ $wrap.RenderTransformOrigin = New-Object System.Windows.Point -ArgumentList 0.5, 0.5
1254
+ $stops = if ($inverse) {
1255
+ # Ink on paper: the same ramp the black shell uses, inverted, so the silhouette keeps its
1256
+ # modelled light (bright at the top of the form) instead of flattening to one grey.
1257
+ @(
1258
+ @{ o = 0.00; c = @(255, 26, 29, 34) },
1259
+ @{ o = 0.26; c = @(255, 44, 49, 57) },
1260
+ @{ o = 0.52; c = @(255, 74, 82, 93) },
1261
+ @{ o = 0.76; c = @(255, 116, 125, 137) },
1262
+ @{ o = 1.00; c = @(255, 158, 166, 176) }
1263
+ )
1264
+ } else {
1265
+ @(
1266
+ @{ o = 0.00; c = @(255, 252, 253, 255) },
1267
+ @{ o = 0.26; c = @(255, 226, 232, 240) },
1268
+ @{ o = 0.52; c = @(255, 190, 201, 214) },
1269
+ @{ o = 0.76; c = @(255, 146, 158, 173) },
1270
+ @{ o = 1.00; c = @(255, 104, 116, 130) }
1271
+ )
1272
+ }
1273
+ [void]$wrap.Children.Add((New-WhaleShape 18.0 17.0 $stops $true))
1274
+ $wrap.IsHitTestVisible = $false
1275
+ return @{ wrap = $wrap; scale = $scale; halo = $null; haloScale = $null }
1276
+ }
1277
+
1278
+ function New-PillBars($ph) {
1279
+ # The information-dense shape: three bars in a fixed 18 DIP slot, so animating their heights never
1280
+ # re-measures the capsule.
1281
+ $panel = New-Object System.Windows.Controls.StackPanel
1282
+ $panel.Orientation = [System.Windows.Controls.Orientation]::Horizontal
1283
+ $panel.Height = 18
1284
+ $panel.VerticalAlignment = [System.Windows.VerticalAlignment]::Center
1285
+ $panel.Margin = New-Object System.Windows.Thickness -ArgumentList 0, 0, 10, 0
1286
+ $bars = New-Object System.Collections.Generic.List[object]
1287
+ for ($i = 0; $i -lt 3; $i++) {
1288
+ $bar = New-Object System.Windows.Shapes.Rectangle
1289
+ $bar.Width = 2.4
1290
+ $bar.Height = 5.0
1291
+ $bar.RadiusX = 1.2; $bar.RadiusY = 1.2
1292
+ $bar.Fill = (New-Solid $ph.base 0.92)
1293
+ $bar.VerticalAlignment = [System.Windows.VerticalAlignment]::Center
1294
+ $bar.Margin = New-Object System.Windows.Thickness -ArgumentList 0, 0, 2.6, 0
1295
+ $bar.IsHitTestVisible = $false
1296
+ [void]$panel.Children.Add($bar)
1297
+ [void]$bars.Add($bar)
1298
+ }
1299
+ return @{ panel = $panel; bars = $bars }
1300
+ }
1301
+
1302
+ function New-PillMark {
1303
+ # A 20 DIP rounded square holding the identity mark, for the `mark` style only -- here the chip IS
1304
+ # the shape, so it has a surface of its own on purpose.
1305
+ #
1306
+ # The paper capsule used to come through this function too, which is why its whale looked like it
1307
+ # had a separate background: it did. `inverse` now draws the bare whale like `orb` does, in ink,
1308
+ # so no style except this one carries a second surface.
1309
+ $chip = New-Object System.Windows.Controls.Border
1310
+ $chip.Width = 20; $chip.Height = 20
1311
+ $chip.CornerRadius = New-Object System.Windows.CornerRadius -ArgumentList 6
1312
+ $chip.Background = New-Solid @(242, 245, 250) 1.0
1313
+ $chip.VerticalAlignment = [System.Windows.VerticalAlignment]::Center
1314
+ $chip.Margin = New-Object System.Windows.Thickness -ArgumentList 0, 0, 9, 0
1315
+ $chip.IsHitTestVisible = $false
1316
+ # Dark whale on the light chip.
1317
+ $ink = @(
1318
+ @{ o = 0.00; c = @(255, 30, 33, 39) },
1319
+ @{ o = 0.60; c = @(255, 12, 14, 18) },
1320
+ @{ o = 1.00; c = @(255, 4, 5, 7) }
1321
+ )
1322
+ $chip.Child = (New-WhaleShape 20.0 13.0 $ink $false)
1323
+ return $chip
1324
+ }
1325
+
1326
+ # ---------------------------------------------------------------- the thin smoke
1327
+ # Thin smoke is not "a few puffs of fog". A row of shapes is countable, and anything countable reads
1328
+ # as ticks on a ruler. What reads as smoke is a DENSITY FIELD: no silhouette, no period, no unit you
1329
+ # can point at, densest at the lip and gone before it reaches the text. So this layer draws no shape
1330
+ # at all; it bakes a noise texture per tone and drifts it.
1331
+ #
1332
+ # The three things that actually decide whether it reads as smoke (each measured, not assumed):
1333
+ # 1. ANISOTROPY. Strands are long in x and short in y. Isotropic noise is a cloud, and a cloud on
1334
+ # a 16 DIP lip reads as dirt. The lattice is therefore sparse across and dense down.
1335
+ # 2. THE THRESHOLD IS A PERCENTILE OF THE FIELD. fBm's mean sits near 0.5 and its range is narrow,
1336
+ # so any fixed cut-off silently produces either nothing or a solid bar. The cut is taken from
1337
+ # the sorted field (62nd / 72nd percentile), so "most of the tile is empty" is a property.
1338
+ # 3. THE VERTICAL ENVELOPE IS BAKED INTO ALPHA. (1-y)^2.1 is what makes it rise from the lip
1339
+ # instead of ending at a hard top edge.
1340
+ # The lattice wraps horizontally, so the tile is seamless and a one-way drift never jumps. Two
1341
+ # layers at different scale and speed drift the same way; the mismatch is where depth comes from.
1342
+ # The soft ends are an OpacityMask on the host, so the mist dissolves instead of being cut off.
1343
+ $script:MIST = [ordered]@{
1344
+ # "A bigger sheet, thinner": wider than the text block so the smoke reads as a sheet lying under
1345
+ # the whole capsule rather than a patch in the middle, and short enough that it never reaches the
1346
+ # type. The old 152 x 17 was a band; a sheet wants more width than height by a wider margin.
1347
+ width = 186.0 # host width in DIP; the mask fades the outer 14% at each end
1348
+ height = 13.0 # host height in DIP
1349
+ inset = 2.0 # distance from the shell's inner bottom edge, DIP
1350
+ }
1351
+
1352
+ function New-SmokeTexture([int]$w, [int]$h, [int]$seed, [double]$cellsX, [double]$cellsY,
1353
+ [double]$gamma, [double]$peak, [double]$cut, [double]$densPow,
1354
+ [int]$cr, [int]$cg, [int]$cb) {
1355
+ # Value-noise fBm on a wrapping lattice, anisotropic, with the vertical envelope in the alpha.
1356
+ # The wrap is what makes the drift seamless: the column right of the last one is the first one.
1357
+ $rnd = New-Object System.Random $seed
1358
+ $oct = 3
1359
+ $lwA = New-Object 'int[]' $oct
1360
+ $lhA = New-Object 'int[]' $oct
1361
+ $dataA = New-Object 'object[]' $oct
1362
+ $norm = 0.0
1363
+ $amp = 1.0
1364
+ for ($o = 0; $o -lt $oct; $o++) {
1365
+ $f = [Math]::Pow(2.0, $o)
1366
+ $lw = [int][Math]::Max(2, [Math]::Round($cellsX * $f))
1367
+ $lh = [int][Math]::Max(2, [Math]::Round($cellsY * $f))
1368
+ $d = New-Object 'double[]' ($lw * $lh)
1369
+ for ($i = 0; $i -lt $d.Length; $i++) { $d[$i] = $rnd.NextDouble() }
1370
+ $lwA[$o] = $lw; $lhA[$o] = $lh; $dataA[$o] = $d
1371
+ $norm += $amp
1372
+ $amp *= 0.5
1373
+ }
1374
+ $fld = New-Object 'double[]' ($w * $h)
1375
+ for ($y = 0; $y -lt $h; $y++) {
1376
+ for ($x = 0; $x -lt $w; $x++) {
1377
+ $n = 0.0
1378
+ $a = 1.0
1379
+ for ($o = 0; $o -lt $oct; $o++) {
1380
+ $lw = $lwA[$o]; $lh = $lhA[$o]; $d = $dataA[$o]
1381
+ $u = ((($x + 0.5) / [double]$w) * $lw)
1382
+ $v = ((($y + 0.5) / [double]$h) * $lh)
1383
+ $i0 = [int][Math]::Floor($u); $j0 = [int][Math]::Floor($v)
1384
+ $fx = $u - $i0; $fy = $v - $j0
1385
+ $sx = $fx * $fx * (3.0 - 2.0 * $fx)
1386
+ $sy = $fy * $fy * (3.0 - 2.0 * $fy)
1387
+ $x0 = $i0 % $lw; if ($x0 -lt 0) { $x0 += $lw }
1388
+ $x1 = ($i0 + 1) % $lw; if ($x1 -lt 0) { $x1 += $lw }
1389
+ $y0 = $j0 % $lh; if ($y0 -lt 0) { $y0 += $lh }
1390
+ $y1 = ($j0 + 1) % $lh; if ($y1 -lt 0) { $y1 += $lh }
1391
+ $v00 = $d[($y0 * $lw) + $x0]; $v10 = $d[($y0 * $lw) + $x1]
1392
+ $v01 = $d[($y1 * $lw) + $x0]; $v11 = $d[($y1 * $lw) + $x1]
1393
+ $top = $v00 + ($v10 - $v00) * $sx
1394
+ $bot = $v01 + ($v11 - $v01) * $sx
1395
+ $n += $a * ($top + ($bot - $top) * $sy)
1396
+ $a *= 0.5
1397
+ }
1398
+ $fld[($y * $w) + $x] = $n / $norm
1399
+ }
1400
+ }
1401
+ # The cut is a percentile of what this seed actually produced, so the fill ratio is a measured
1402
+ # property of the tile rather than a guess that happens to look right on one monitor.
1403
+ $sorted = New-Object 'double[]' $fld.Length
1404
+ [Array]::Copy($fld, $sorted, $fld.Length)
1405
+ [Array]::Sort($sorted)
1406
+ $lo = $sorted[[int][Math]::Min($sorted.Length - 1, $sorted.Length * $cut)]
1407
+ $hi = $sorted[[int][Math]::Min($sorted.Length - 1, $sorted.Length * 0.995)]
1408
+ $span = $hi - $lo
1409
+ if ($span -le 0.0001) { $span = 0.0001 }
1410
+ $px = New-Object 'byte[]' ($w * $h * 4)
1411
+ for ($y = 0; $y -lt $h; $y++) {
1412
+ # Row 0 is the TOP of the band and row h-1 is the lip, because the host is pinned to the
1413
+ # shell's bottom edge. The envelope therefore grows with y: writing (1-y) here put the densest
1414
+ # smoke at the top of the band and left the lip empty, which is backwards.
1415
+ $ny = if ($h -gt 1) { $y / [double]($h - 1) } else { 1.0 }
1416
+ $dens = [Math]::Pow($ny, $densPow)
1417
+ for ($x = 0; $x -lt $w; $x++) {
1418
+ $t = ($fld[($y * $w) + $x] - $lo) / $span
1419
+ if ($t -lt 0.0) { $t = 0.0 } elseif ($t -gt 1.0) { $t = 1.0 }
1420
+ $t = $t * $t * (3.0 - 2.0 * $t)
1421
+ $t = [Math]::Pow($t, $gamma)
1422
+ $al = [int][Math]::Round(255.0 * $peak * $dens * $t)
1423
+ if ($al -gt 255) { $al = 255 } elseif ($al -lt 0) { $al = 0 }
1424
+ $i = (($y * $w) + $x) * 4
1425
+ # Bgra32, straight alpha: premultiplying here would make a low-alpha veil darker than the
1426
+ # tone that was asked for.
1427
+ $px[$i] = [byte]$cb; $px[$i + 1] = [byte]$cg; $px[$i + 2] = [byte]$cr; $px[$i + 3] = [byte]$al
1428
+ }
1429
+ }
1430
+ $bmp = [System.Windows.Media.Imaging.BitmapSource]::Create($w, $h, 96.0, 96.0,
1431
+ [System.Windows.Media.PixelFormats]::Bgra32, $null, $px, $w * 4)
1432
+ $bmp.Freeze()
1433
+ return $bmp
1434
+ }
1435
+
1436
+ $script:smokeCache = @{}
1437
+ function Get-SmokeTexture([string]$key, [scriptblock]$build) {
1438
+ # Baking costs a few hundred noise samples per texel, and Render-Layout rebuilds the tree on every
1439
+ # phase/look change. The texture is immutable and frozen, so it is built once per tone.
1440
+ if ($script:smokeCache.ContainsKey($key)) { return $script:smokeCache[$key] }
1441
+ $tex = & $build
1442
+ $script:smokeCache[$key] = $tex
1443
+ return $tex
1444
+ }
1445
+
1446
+ function New-SmokeLayer($tex, [double]$tileW, [double]$layerH, [double]$hostW, [double]$opacity, [double]$driftSec, [double]$blurPx, [double]$yoff) {
1447
+ # One tile is drawn once and repeated by the brush; the element is two tiles wider than the host
1448
+ # and slides exactly one tile, so the wrap is invisible and the motion never reverses. A repeating
1449
+ # AutoReverse animation is exactly what made the old lobes look like they were breathing.
1450
+ $brush = New-Object System.Windows.Media.ImageBrush
1451
+ $brush.ImageSource = $tex
1452
+ $brush.Stretch = [System.Windows.Media.Stretch]::Fill
1453
+ $brush.TileMode = [System.Windows.Media.TileMode]::Tile
1454
+ $brush.ViewportUnits = [System.Windows.Media.BrushMappingMode]::Absolute
1455
+ $brush.Viewport = New-Object System.Windows.Rect -ArgumentList 0.0, 0.0, $tileW, $layerH
1456
+ $brush.AlignmentX = [System.Windows.Media.AlignmentX]::Left
1457
+ $brush.AlignmentY = [System.Windows.Media.AlignmentY]::Top
1458
+ $brush.Freeze()
1459
+ $layer = New-Object System.Windows.Controls.Border
1460
+ $layer.Width = $hostW + ($tileW * 2.0)
1461
+ $layer.Height = $layerH
1462
+ $layer.HorizontalAlignment = [System.Windows.HorizontalAlignment]::Left
1463
+ $layer.VerticalAlignment = [System.Windows.VerticalAlignment]::Bottom
1464
+ $layer.Margin = New-Object System.Windows.Thickness -ArgumentList 0, 0, 0, ([double]$yoff)
1465
+ $layer.Background = $brush
1466
+ $layer.Opacity = $opacity
1467
+ $layer.IsHitTestVisible = $false
1468
+ if ($blurPx -gt 0) {
1469
+ # A small blur removes the last lattice anisotropy; the softness itself is already in the
1470
+ # texture, so this stays cheap and there is still no edge to see.
1471
+ $blur = New-Object System.Windows.Media.Effects.BlurEffect
1472
+ $blur.Radius = $blurPx
1473
+ $blur.KernelType = [System.Windows.Media.Effects.KernelType]::Gaussian
1474
+ $layer.Effect = $blur
1475
+ }
1476
+ $move = New-Object System.Windows.Media.TranslateTransform -ArgumentList 0.0, 0.0
1477
+ $layer.RenderTransform = $move
1478
+ $drift = New-Object System.Windows.Media.Animation.DoubleAnimation
1479
+ $drift.From = 0.0
1480
+ $drift.To = -$tileW
1481
+ $drift.Duration = [TimeSpan]::FromMilliseconds([double]$driftSec * 1000.0)
1482
+ $drift.RepeatBehavior = [System.Windows.Media.Animation.RepeatBehavior]::Forever
1483
+ $move.BeginAnimation([System.Windows.Media.TranslateTransform]::XProperty, $drift)
1484
+ return $layer
1485
+ }
1486
+
1487
+ function New-PillFloor([bool]$inverse) {
1488
+ # The smoke lives in its own window-level layer instead of inside the text Border: Border child
1489
+ # layout kept centring it on the text row. Here it is a bottom-pinned host, and Build-Pill pins
1490
+ # that host to the shell's inner floor.
1491
+ #
1492
+ # The host carries NO width of its own and stretches instead. A fixed width participates in the
1493
+ # capsule's measurement: WPF takes the widest child, so a 186 DIP smoke host made the pill 218 DIP
1494
+ # wide with ~80 empty DIP of shell to the right of the text. Measured width comes from the TEXT,
1495
+ # and the smoke sheet simply fills whatever the text produced.
1496
+ $M = $script:MIST
1497
+ $floor = New-Object System.Windows.Controls.Grid
1498
+ $floor.Height = [double]$M.height
1499
+ $floor.HorizontalAlignment = [System.Windows.HorizontalAlignment]::Stretch
1500
+ $floor.VerticalAlignment = [System.Windows.VerticalAlignment]::Bottom
1501
+ $floor.ClipToBounds = $true
1502
+ $floor.IsHitTestVisible = $false
1503
+
1504
+ # The smoke is LIGHT on a dark shell: a veil of the capsule's own accent, brightest where it is
1505
+ # densest. On the paper capsule that inverts badly -- the same veil reads as a grey smudge along
1506
+ # the lip, because on a near-white surface any darkening is dirt rather than smoke. So the paper
1507
+ # shell does not get a darker mist; it gets a WHITE one, which is how thin smoke actually appears
1508
+ # when the light behind it is stronger than the surface: a bright haze, not a stain.
1509
+ $mr = if ($inverse) { 255 } else { 236 }
1510
+ $mg = if ($inverse) { 255 } else { 244 }
1511
+ $mb = if ($inverse) { 255 } else { 254 }
1512
+
1513
+ # The source: a half-ellipse of light right at the lip, so the mist has somewhere to come from.
1514
+ # It has no edge of its own -- the radial falloff is the whole shape. Wider and flatter than the
1515
+ # layer it feeds, because the sheet should look like it is spreading out of a broad seam.
1516
+ $anchor = New-Object System.Windows.Controls.Border
1517
+ $anchor.Width = 140; $anchor.Height = 3.8
1518
+ $anchor.HorizontalAlignment = [System.Windows.HorizontalAlignment]::Center
1519
+ $anchor.VerticalAlignment = [System.Windows.VerticalAlignment]::Bottom
1520
+ $anchor.Opacity = 0.32
1521
+ $anchor.IsHitTestVisible = $false
1522
+ $ab = New-Object System.Windows.Media.RadialGradientBrush
1523
+ $ab.Center = New-Object System.Windows.Point -ArgumentList 0.5, 1.0
1524
+ $ab.GradientOrigin = New-Object System.Windows.Point -ArgumentList 0.5, 1.0
1525
+ $ab.RadiusX = 0.5; $ab.RadiusY = 1.0
1526
+ foreach ($sp in @(
1527
+ @{ o = 0.00; a = 110 },
1528
+ @{ o = 0.50; a = 26 },
1529
+ @{ o = 1.00; a = 0 }
1530
+ )) {
1531
+ $gs = New-Object System.Windows.Media.GradientStop
1532
+ $gs.Color = [System.Windows.Media.Color]::FromArgb([byte]$sp.a, [byte]$mr, [byte]$mg, [byte]$mb)
1533
+ $gs.Offset = [double]$sp.o
1534
+ [void]$ab.GradientStops.Add($gs)
1535
+ }
1536
+ $anchor.Background = $ab
1537
+ [void]$floor.Children.Add($anchor)
1538
+
1539
+ # Far layer: long slow billows, wider tile -- the body of the haze. Fewer cells across than the
1540
+ # near layer, so a tile holds a few long strands instead of a texture, and a longer tile means the
1541
+ # pattern is bigger than the capsule before it repeats.
1542
+ $farTex = Get-SmokeTexture (('far|' + [string]$inverse)) {
1543
+ New-SmokeTexture 192 32 7301 4.2 1.0 1.4 1.00 0.66 3.8 $mr $mg $mb
1544
+ }
1545
+ [void]$floor.Children.Add((New-SmokeLayer $farTex 124.0 12.0 ([double]$M.width) $(if ($inverse) { 0.30 } else { 0.58 }) 55.0 6.5 0.7))
1546
+ # Near layer: finer filaments, quicker, shorter tile -- the surface of it. The two periods never
1547
+ # divide into each other, so the pair never falls back into a visible loop. Thin on purpose: this
1548
+ # is the layer that would make the sheet read as a wash if it were strong.
1549
+ $nearTex = Get-SmokeTexture (('near|' + [string]$inverse)) {
1550
+ New-SmokeTexture 128 24 4409 7.4 1.4 1.1 0.66 0.72 3.4 $mr $mg $mb
1551
+ }
1552
+ [void]$floor.Children.Add((New-SmokeLayer $nearTex 83.0 13.0 ([double]$M.width) $(if ($inverse) { 0.14 } else { 0.28 }) 31.0 3.6 0.0))
1553
+
1554
+ # The ends dissolve: an alpha ramp on the host, so the smoke thins out instead of stopping. The
1555
+ # plateau is wide (10%..90%) because the sheet is supposed to span the capsule, not sit in its
1556
+ # middle: a narrow plateau made the previous build read as a patch under the type.
1557
+ $mask = New-Object System.Windows.Media.LinearGradientBrush
1558
+ $mask.StartPoint = New-Object System.Windows.Point -ArgumentList 0.0, 0.5
1559
+ $mask.EndPoint = New-Object System.Windows.Point -ArgumentList 1.0, 0.5
1560
+ foreach ($st in @(
1561
+ @{ o = 0.00; a = 0 },
1562
+ @{ o = 0.10; a = 255 },
1563
+ @{ o = 0.50; a = 255 },
1564
+ @{ o = 0.90; a = 255 },
1565
+ @{ o = 1.00; a = 0 }
1566
+ )) {
1567
+ $gs = New-Object System.Windows.Media.GradientStop
1568
+ $gs.Color = [System.Windows.Media.Color]::FromArgb([byte]$st.a, 0, 0, 0)
1569
+ $gs.Offset = [double]$st.o
1570
+ [void]$mask.GradientStops.Add($gs)
1571
+ }
1572
+ $floor.OpacityMask = $mask
1573
+ return $floor
1574
+ }
1575
+
975
1576
  function Build-Pill($ph) {
1577
+ # Four shapes, two things to decide: the shell (black or paper) and the mark.
1578
+ #
1579
+ # ALL FOUR are the same size: 44 DIP, 22 DIP radius. `inverse` used to be grouped with `wave` as
1580
+ # a "dense" two-line shape, so the paper capsule came out 56 DIP tall with a 25 DIP radius and
1581
+ # switching to it moved the pill under the pointer. Size is not part of what "paper" means, so the
1582
+ # shell colour and the height are decided separately now.
1583
+ #
1584
+ # The mark is the whale on every style. `orb` and `inverse` draw it bare on the shell; `mark`
1585
+ # keeps the chip, because that chip IS the shape; `wave` shows bars instead.
1586
+ $style = [string]$script:S.pillStyle
1587
+ if ($style -eq '') { $style = 'orb' }
1588
+ $inverse = ($style -eq 'inverse')
976
1589
  $border = New-Object System.Windows.Controls.Border
977
- $border.CornerRadius = New-Object System.Windows.CornerRadius -ArgumentList 18
978
- # dark glass unless the plugin hands over a pillBg triple
979
- $bgT = $script:S.pillBg; if ($null -eq $bgT) { $bgT = @(27, 32, 39) }
980
- $border.Background = (New-Object System.Windows.Media.SolidColorBrush -ArgumentList ([System.Windows.Media.Color]::FromArgb([byte]219, [byte]$bgT[0], [byte]$bgT[1], [byte]$bgT[2])))
981
- $border.BorderBrush = (New-Solid $ph.base 0.5) # base colour at 0.5
1590
+ $border.CornerRadius = New-Object System.Windows.CornerRadius -ArgumentList 22
1591
+ $border.MinHeight = 44
1592
+ # FIXED width. The capsule used to size to its content, which made its length a function of the
1593
+ # text: the thin-smoke host (186 DIP) was the widest child and stretched every capsule to 218 DIP
1594
+ # with ~80 empty DIP of shell past the type. A fixed length keeps the silhouette stable --
1595
+ # constant shape, constant position of everything inside it, no layout shift when the state word
1596
+ # changes -- and the smoke sheet fills whatever this width is instead of dictating it.
1597
+ # 172 DIP: mark(18) + gap(9) + heading(~34) + gap(10) + longest state word(~78) + padding(26).
1598
+ # 160 was tried and squeezed the heading against the state word; the user settled on 172.
1599
+ $border.Width = 172.0
1600
+ $bgT = $script:S.pillBg; if ($null -eq $bgT) { $bgT = @(11, 13, 16) }
1601
+ $bgBrush = New-Object System.Windows.Media.LinearGradientBrush
1602
+ $bgBrush.StartPoint = New-Object System.Windows.Point -ArgumentList 0.0, 0.0
1603
+ $bgBrush.EndPoint = New-Object System.Windows.Point -ArgumentList 0.0, 1.0
1604
+ $bg0 = New-Object System.Windows.Media.GradientStop
1605
+ $bg1 = New-Object System.Windows.Media.GradientStop
1606
+ if ($inverse) {
1607
+ $bgT = @(244, 246, 249)
1608
+ $bg0.Color = [System.Windows.Media.Color]::FromArgb([byte]252, 255, 255, 255); $bg0.Offset = 0.0
1609
+ $bg1.Color = [System.Windows.Media.Color]::FromArgb([byte]245, [byte]233, [byte]237, [byte]242); $bg1.Offset = 1.0
1610
+ } else {
1611
+ $bg0.Color = [System.Windows.Media.Color]::FromArgb([byte]248, [byte]$bgT[0], [byte]$bgT[1], [byte]$bgT[2]); $bg0.Offset = 0.0
1612
+ $bg1.Color = [System.Windows.Media.Color]::FromArgb([byte]236, [byte]$bgT[0], [byte]$bgT[1], [byte]$bgT[2]); $bg1.Offset = 1.0
1613
+ }
1614
+ [void]$bgBrush.GradientStops.Add($bg0); [void]$bgBrush.GradientStops.Add($bg1)
1615
+ $border.Background = $bgBrush
1616
+ # A vertical hairline (brighter on top) instead of a coloured stroke: coloured borders read as
1617
+ # a badge, light-on-glass reads as a surface. On paper the hairline turns dark for the same reason.
1618
+ $edge = New-Object System.Windows.Media.LinearGradientBrush
1619
+ $edge.StartPoint = New-Object System.Windows.Point -ArgumentList 0.0, 0.0
1620
+ $edge.EndPoint = New-Object System.Windows.Point -ArgumentList 0.0, 1.0
1621
+ $e0 = New-Object System.Windows.Media.GradientStop
1622
+ $e1 = New-Object System.Windows.Media.GradientStop
1623
+ if ($inverse) {
1624
+ $e0.Color = [System.Windows.Media.Color]::FromArgb([byte]44, 0, 0, 0); $e0.Offset = 0.0
1625
+ $e1.Color = [System.Windows.Media.Color]::FromArgb([byte]10, 0, 0, 0); $e1.Offset = 1.0
1626
+ } else {
1627
+ $e0.Color = [System.Windows.Media.Color]::FromArgb([byte]54, 255, 255, 255); $e0.Offset = 0.0
1628
+ $e1.Color = [System.Windows.Media.Color]::FromArgb([byte]10, 255, 255, 255); $e1.Offset = 1.0
1629
+ }
1630
+ [void]$edge.GradientStops.Add($e0); [void]$edge.GradientStops.Add($e1)
1631
+ $border.BorderBrush = $edge
982
1632
  $border.BorderThickness = New-Object System.Windows.Thickness -ArgumentList 1.0
983
- $border.Padding = New-Object System.Windows.Thickness -ArgumentList 15, 8, 15, 9
1633
+ # Symmetric padding, and the content grid CENTRED: the shell is a fixed-length capsule now, so
1634
+ # left-aligned content would pile all the slack on the right (the "右边空间分明无用" complaint).
1635
+ # Centring splits the remaining width evenly, whatever the state word measures.
1636
+ $border.Padding = New-Object System.Windows.Thickness -ArgumentList 13, 0, 13, 0
1637
+ # The bloom is the phase accent at low opacity, spread evenly (depth 0), so the capsule sits in its
1638
+ # own light instead of casting a grey office shadow.
1639
+ $glow = New-Object System.Windows.Media.Effects.DropShadowEffect
1640
+ if ($inverse) {
1641
+ $glow.Color = [System.Windows.Media.Color]::FromRgb(214, 220, 228)
1642
+ $glow.Opacity = 0.30
1643
+ } else {
1644
+ $glow.Color = [System.Windows.Media.Color]::FromRgb([byte]$ph.base[0], [byte]$ph.base[1], [byte]$ph.base[2])
1645
+ $glow.Opacity = 0.40
1646
+ }
1647
+ $glow.BlurRadius = 24
1648
+ $glow.ShadowDepth = 0
1649
+ $border.Effect = $glow
1650
+ $border.IsHitTestVisible = $false
1651
+
1652
+ $grid = New-Object System.Windows.Controls.Grid
1653
+ $grid.VerticalAlignment = [System.Windows.VerticalAlignment]::Center
1654
+ # The state column STRETCHES and its text right-aligns inside it. The state word changes length
1655
+ # per phase (正在操控电脑 is 6 chars, 已停止 is 3), so left-aligning it would leave a different
1656
+ # right-hand gap per phase on a fixed-length shell. Stretching the column and right-aligning the
1657
+ # text pins the text's RIGHT edge to one constant x: the stopped capsule ends its wording exactly
1658
+ # where the acting one does, and the slack accumulates between the mark and the text instead.
1659
+ $grid.HorizontalAlignment = [System.Windows.HorizontalAlignment]::Stretch
1660
+ # Three columns: mark | DSH heading | state word. The mark and the heading keep FIXED positions
1661
+ # (same x as always); only the state word lives in the stretching column, right-aligned, so its
1662
+ # right edge stays at one constant x no matter how long the phase wording is. The gap between the
1663
+ # heading and the state word is elastic and absorbs the length difference.
1664
+ $c0 = New-Object System.Windows.Controls.ColumnDefinition
1665
+ $c0.Width = [System.Windows.GridLength]::Auto
1666
+ $c1 = New-Object System.Windows.Controls.ColumnDefinition
1667
+ $c1.Width = [System.Windows.GridLength]::Auto
1668
+ $c2 = New-Object System.Windows.Controls.ColumnDefinition
1669
+ # ::new() is the form that works here: the two-argument New-Object variant fails to convert the
1670
+ # enum parameter on this framework build (measured: internal_error, 无法转换 GridLength 参数 1).
1671
+ $c2.Width = [System.Windows.GridLength]::new(1.0, [System.Windows.GridUnitType]::Star)
1672
+ [void]$grid.ColumnDefinitions.Add($c0); [void]$grid.ColumnDefinitions.Add($c1); [void]$grid.ColumnDefinitions.Add($c2)
1673
+
1674
+ $orb = $null
1675
+ $bars = $null
1676
+ $indicator = $null
1677
+ switch ($style) {
1678
+ 'orb' { $orb = New-PillOrb $ph $false; $orb.wrap.Margin = New-Object System.Windows.Thickness -ArgumentList 0, 0, 9, 0; $indicator = $orb.wrap }
1679
+ 'wave' { $bars = New-PillBars $ph; $indicator = $bars.panel }
1680
+ 'mark' { $indicator = New-PillMark }
1681
+ # Same bare whale as `orb`, inked for the paper shell: no chip, same 18 DIP slot, same position.
1682
+ 'inverse' { $orb = New-PillOrb $ph $true; $orb.wrap.Margin = New-Object System.Windows.Thickness -ArgumentList 0, 0, 9, 0; $indicator = $orb.wrap }
1683
+ default { $orb = New-PillOrb $ph $false; $orb.wrap.Margin = New-Object System.Windows.Thickness -ArgumentList 0, 0, 9, 0; $indicator = $orb.wrap }
1684
+ }
1685
+ [System.Windows.Controls.Grid]::SetColumn($indicator, 0)
1686
+ [void]$grid.Children.Add($indicator)
1687
+
984
1688
  $stack = New-Object System.Windows.Controls.StackPanel
985
1689
  $stack.Orientation = [System.Windows.Controls.Orientation]::Vertical
1690
+ $stack.VerticalAlignment = [System.Windows.VerticalAlignment]::Center
1691
+ # The HEADING ("DSH", bold) lives in its own fixed column, so its x never moves.
986
1692
  $txt = New-Object System.Windows.Controls.TextBlock
987
- $txt.HorizontalAlignment = [System.Windows.HorizontalAlignment]::Center
988
- $txt.FontSize = 14.0
1693
+ $txt.HorizontalAlignment = [System.Windows.HorizontalAlignment]::Left
1694
+ $txt.FontSize = 13.0
989
1695
  $txt.FontFamily = New-Object System.Windows.Media.FontFamily -ArgumentList $script:S.chosenFont
990
- $txt.FontWeight = [System.Windows.FontWeights]::SemiBold
991
- $fgT = $script:S.pillText; if ($null -eq $fgT) { $fgT = @(236, 243, 255) }
1696
+ $fgT = $script:S.pillText; if ($null -eq $fgT) { $fgT = @(242, 245, 250) }
1697
+ if ($inverse) { $fgT = @(8, 9, 11) }
992
1698
  $txt.Foreground = (New-Solid $fgT 1.0)
993
- $txt.Text = ''
1699
+ $brandRun = New-Object System.Windows.Documents.Run -ArgumentList $script:TEXT.brand
1700
+ $brandRun.FontWeight = [System.Windows.FontWeights]::Bold
1701
+ [void]$txt.Inlines.Add($brandRun)
1702
+ # Column 1 is a vertical pair: the fixed heading on top, the (rare) second line under it. Both
1703
+ # keep their x because the column is Auto-sized and left-aligned.
1704
+ $stack = New-Object System.Windows.Controls.StackPanel
1705
+ $stack.Orientation = [System.Windows.Controls.Orientation]::Vertical
1706
+ $stack.VerticalAlignment = [System.Windows.VerticalAlignment]::Center
1707
+ [void]$stack.Children.Add($txt)
1708
+ # The STATE word lives in the stretching column, right-aligned: its right edge is the one
1709
+ # constant the person compares across phases (正在操控电脑 vs 已停止 differ by 3 chars, and on a
1710
+ # fixed-length shell that difference must show up in the middle gap, never in the right margin).
1711
+ $restTxt = New-Object System.Windows.Controls.TextBlock
1712
+ $restTxt.HorizontalAlignment = [System.Windows.HorizontalAlignment]::Right
1713
+ $restTxt.VerticalAlignment = [System.Windows.VerticalAlignment]::Center
1714
+ $restTxt.FontSize = 13.0
1715
+ $restTxt.FontFamily = New-Object System.Windows.Media.FontFamily -ArgumentList $script:S.chosenFont
1716
+ $restTxt.Foreground = (New-Solid $fgT 0.74)
1717
+ $restRun = New-Object System.Windows.Documents.Run -ArgumentList ''
1718
+ [void]$restTxt.Inlines.Add($restRun)
1719
+ [System.Windows.Controls.Grid]::SetColumn($restTxt, 2)
1720
+ [void]$grid.Children.Add($restTxt)
994
1721
  $sub = New-Object System.Windows.Controls.TextBlock
995
- $sub.HorizontalAlignment = [System.Windows.HorizontalAlignment]::Center
996
- $sub.FontSize = 11.5
1722
+ $sub.HorizontalAlignment = [System.Windows.HorizontalAlignment]::Left
1723
+ $sub.FontSize = 10.5
997
1724
  $sub.FontFamily = New-Object System.Windows.Media.FontFamily -ArgumentList $script:S.chosenFont
998
- $sub.Foreground = (New-Solid @(159, 179, 209) 0.95)
1725
+ $sub.Foreground = if ($inverse) { New-Solid @(90, 96, 104) 0.70 } else { New-Solid @(214, 221, 230) 0.62 }
999
1726
  $sub.Margin = New-Object System.Windows.Thickness -ArgumentList 0, 1, 0, 0
1000
1727
  $sub.Text = ''
1001
1728
  $sub.Visibility = [System.Windows.Visibility]::Collapsed
1002
- [void]$stack.Children.Add($txt)
1003
1729
  [void]$stack.Children.Add($sub)
1004
- $border.Child = $stack
1005
- $border.IsHitTestVisible = $false
1006
- return @{ border = $border; text = $txt; sub = $sub }
1730
+ [System.Windows.Controls.Grid]::SetColumn($stack, 1)
1731
+ [void]$grid.Children.Add($stack)
1732
+
1733
+ # The smoke sits on the inner lip of the shell, inset by MIST.inset so it never reads as an outer
1734
+ # underline. It is its own full-size layer; the text grid only carries the orb and the runs.
1735
+ #
1736
+ # The layer is skipped entirely when the person turned it off, rather than being made transparent:
1737
+ # a zero-opacity layer still costs a tile brush, a blur and a running drift animation for every
1738
+ # frame of the capsule's life.
1739
+ $root = New-Object System.Windows.Controls.Grid
1740
+ $root.ClipToBounds = $true
1741
+ [void]$root.Children.Add($grid)
1742
+ if ($script:S.mistOn) {
1743
+ $floor = New-PillFloor $inverse
1744
+ $floor.Margin = New-Object System.Windows.Thickness -ArgumentList 0, 0, 0, ([double]$script:MIST.inset)
1745
+ [void]$root.Children.Add($floor)
1746
+ }
1747
+ $border.Child = $root
1748
+
1749
+ # Scale from slightly small and translucent: the island "opens" instead of popping in.
1750
+ $scale = New-Object System.Windows.Media.ScaleTransform -ArgumentList 0.90, 0.90
1751
+ $border.RenderTransform = $scale
1752
+ $border.RenderTransformOrigin = New-Object System.Windows.Point -ArgumentList 0.5, 0.5
1753
+ $border.Opacity = 0.0
1754
+ return @{
1755
+ border = $border; text = $txt; sub = $sub; scale = $scale; brandRun = $brandRun; restRun = $restRun
1756
+ orb = if ($null -ne $orb) { $orb.wrap } else { $null }
1757
+ orbScale = if ($null -ne $orb) { $orb.scale } else { $null }
1758
+ orbHalo = if ($null -ne $orb) { $orb.halo } else { $null }
1759
+ orbHaloScale = if ($null -ne $orb) { $orb.haloScale } else { $null }
1760
+ bars = if ($null -ne $bars) { $bars.bars } else { @() }
1761
+ }
1762
+ }
1763
+
1764
+ function Start-PillIntro {
1765
+ if ($null -eq $script:S.pill) { return }
1766
+ $dur = [TimeSpan]::FromMilliseconds(340)
1767
+ $ease = New-Object System.Windows.Media.Animation.BackEase
1768
+ $ease.EasingMode = [System.Windows.Media.Animation.EasingMode]::EaseOut
1769
+ $ease.Amplitude = 0.28
1770
+ $sx = New-Object System.Windows.Media.Animation.DoubleAnimation -ArgumentList 0.90, 1.0, $dur
1771
+ $sx.EasingFunction = $ease
1772
+ $sy = New-Object System.Windows.Media.Animation.DoubleAnimation -ArgumentList 0.90, 1.0, $dur
1773
+ $sy.EasingFunction = $ease
1774
+ $op = New-Object System.Windows.Media.Animation.DoubleAnimation -ArgumentList 0.0, 1.0, ([TimeSpan]::FromMilliseconds(180))
1775
+ if ($null -ne $script:S.pillScale) {
1776
+ $script:S.pillScale.BeginAnimation([System.Windows.Media.ScaleTransform]::ScaleXProperty, $sx)
1777
+ $script:S.pillScale.BeginAnimation([System.Windows.Media.ScaleTransform]::ScaleYProperty, $sy)
1778
+ }
1779
+ $script:S.pill.BeginAnimation([System.Windows.UIElement]::OpacityProperty, $op)
1780
+ }
1781
+
1782
+ function Start-PillOrb([bool]$on) {
1783
+ # The whale is fixed in size. Only its tail control points move; there is no whole-icon breathing
1784
+ # and no halo bloom left from the glass-bead version.
1785
+ $wrap = $script:S.pillOrb
1786
+ if ($null -eq $wrap) { return }
1787
+ $scale = $script:S.pillOrbScale
1788
+ $halo = $script:S.pillOrbHalo
1789
+ $haloScale = $script:S.pillOrbHaloScale
1790
+ if (-not $on) {
1791
+ try {
1792
+ $scale.BeginAnimation([System.Windows.Media.ScaleTransform]::ScaleXProperty, $null)
1793
+ $scale.BeginAnimation([System.Windows.Media.ScaleTransform]::ScaleYProperty, $null)
1794
+ if ($null -ne $halo) { $halo.BeginAnimation([System.Windows.UIElement]::OpacityProperty, $null) }
1795
+ if ($null -ne $haloScale) {
1796
+ $haloScale.BeginAnimation([System.Windows.Media.ScaleTransform]::ScaleXProperty, $null)
1797
+ $haloScale.BeginAnimation([System.Windows.Media.ScaleTransform]::ScaleYProperty, $null)
1798
+ }
1799
+ } catch { }
1800
+ $scale.ScaleX = 1.0; $scale.ScaleY = 1.0
1801
+ if ($null -ne $halo) { $halo.Opacity = 0.30 }
1802
+ if ($null -ne $haloScale) { $haloScale.ScaleX = 1.0; $haloScale.ScaleY = 1.0 }
1803
+ return
1804
+ }
1805
+ $scale.ScaleX = 1.0; $scale.ScaleY = 1.0
1806
+ if ($null -ne $halo) {
1807
+ $bloom = New-Object System.Windows.Media.Animation.DoubleAnimation
1808
+ $bloom.From = 0.24; $bloom.To = 0.62
1809
+ $bloom.Duration = [TimeSpan]::FromMilliseconds(2600)
1810
+ $bloom.AutoReverse = $true
1811
+ $bloom.RepeatBehavior = [System.Windows.Media.Animation.RepeatBehavior]::Forever
1812
+ $bloom.EasingFunction = $ease
1813
+ $halo.BeginAnimation([System.Windows.UIElement]::OpacityProperty, $bloom)
1814
+ }
1815
+ if ($null -ne $haloScale) {
1816
+ foreach ($axis in @([System.Windows.Media.ScaleTransform]::ScaleXProperty, [System.Windows.Media.ScaleTransform]::ScaleYProperty)) {
1817
+ $pulse = New-Object System.Windows.Media.Animation.DoubleAnimation
1818
+ $pulse.From = 0.92; $pulse.To = 1.10
1819
+ $pulse.Duration = [TimeSpan]::FromMilliseconds(2600)
1820
+ $pulse.AutoReverse = $true
1821
+ $pulse.RepeatBehavior = [System.Windows.Media.Animation.RepeatBehavior]::Forever
1822
+ $pulse.EasingFunction = $ease
1823
+ $haloScale.BeginAnimation($axis, $pulse)
1824
+ }
1825
+ }
1826
+ }
1827
+
1828
+ function Start-PillBars([bool]$on) {
1829
+ # The wave style's own heartbeat: three bars at staggered delays, so the group reads as sound rather
1830
+ # than three independent dots. Off freezes them mid-height and lets the colour carry the state.
1831
+ $bars = @($script:S.pillBars)
1832
+ if ($bars.Count -eq 0) { return }
1833
+ $ease = New-Object System.Windows.Media.Animation.SineEase
1834
+ $ease.EasingMode = [System.Windows.Media.Animation.EasingMode]::EaseInOut
1835
+ $delays = @(0, 160, 320)
1836
+ for ($i = 0; $i -lt $bars.Count; $i++) {
1837
+ $bar = $bars[$i]
1838
+ if (-not $on) {
1839
+ try { $bar.BeginAnimation([System.Windows.FrameworkElement]::HeightProperty, $null) } catch { }
1840
+ $bar.Height = 5.0
1841
+ continue
1842
+ }
1843
+ $anim = New-Object System.Windows.Media.Animation.DoubleAnimation
1844
+ $anim.From = 4.0; $anim.To = 15.0
1845
+ $anim.Duration = [TimeSpan]::FromMilliseconds(620)
1846
+ $anim.AutoReverse = $true
1847
+ $anim.RepeatBehavior = [System.Windows.Media.Animation.RepeatBehavior]::Forever
1848
+ $anim.EasingFunction = $ease
1849
+ $anim.BeginTime = [TimeSpan]::FromMilliseconds($delays[$i % 3])
1850
+ $bar.BeginAnimation([System.Windows.FrameworkElement]::HeightProperty, $anim)
1851
+ }
1007
1852
  }
1008
1853
 
1009
1854
  function Clear-Canvas {
1855
+ # Every call throws away the visual tree, so every call restarts the intro animation. Counting it
1856
+ # is what makes "one flash per action" measurable instead of a matter of opinion: a run that does
1857
+ # twenty actions must show layoutBuilds = 1, not 20.
1858
+ $script:S.layoutBuilds += 1
1010
1859
  if ($null -ne $script:S.canvas) { $script:S.canvas.Children.Clear() }
1011
- $script:S.ring = @(); $script:S.bloom = @(); $script:S.outline = $null
1860
+ $script:S.ring = @(); $script:S.bloom = @()
1012
1861
  $script:S.pill = $null; $script:S.pillText = $null; $script:S.pillSub = $null
1862
+ $script:S.pillOrb = $null; $script:S.pillOrbScale = $null; $script:S.pillOrbHalo = $null; $script:S.pillOrbHaloScale = $null; $script:S.pillBars = @()
1863
+ $script:S.pillScale = $null; $script:S.pillBrandRun = $null; $script:S.pillRestRun = $null
1013
1864
  $script:S.halo = $null; $script:S.haloBlooms = @(); $script:S.haloOn = $false
1014
1865
  $script:S.haloCurs = $null; $script:S.haloShape = [IntPtr]::Zero
1015
1866
  }
1016
1867
 
1017
1868
  # Rebuilds the visual set for the current monitor geometry + phase. The Window object is never
1018
1869
  # touched here, so the HWND (and hwndCreateCount) survives every phase change.
1870
+ function Update-PhaseLook {
1871
+ # Recolour the live tree for the current phase, WITHOUT rebuilding it.
1872
+ #
1873
+ # The phase used to be part of Render-Layout's cache key, so acting -> stopped cleared the canvas
1874
+ # and rebuilt every visual, which replayed the intro animation: the person saw the capsule turn
1875
+ # red and then pop in again -- "the stopped state flashes twice". A phase change only needs new
1876
+ # colours, so this rewrites the brushes that depend on the phase and leaves geometry, layout and
1877
+ # the running animations alone.
1878
+ #
1879
+ # Only the ring/bloom and the pill's own accent depend on the phase; the shell colour, the text
1880
+ # and the mark come from the palette/style and are already correct.
1881
+ if ($null -eq $script:S.canvas) { return }
1882
+ $ph = $script:PH[$script:S.phase]
1883
+ if ($null -eq $ph) { return }
1884
+ $m = $script:S.monitorBounds
1885
+ if ($null -eq $m) { return }
1886
+ $sc = [double]$script:S.scale; if ($sc -le 0) { $sc = 1.0 }
1887
+ $W = [double]$m.w / $sc
1888
+ $H = [double]$m.h / $sc
1889
+ $T = [double]$CFG.ringPx / $sc
1890
+ $dark = Test-DarkAmbient $ph.g0
1891
+ $mask = if ($dark) { 'New-Vignette' } else { 'New-Fade' }
1892
+ # Rebuild only the four ring/bloom bars in place: they are pure colour + mask, no layout state.
1893
+ $E = $T * 4.0
1894
+ # `$edges`, not `$specs`: a gate forbids that name outside the smoke builder, where it used to be
1895
+ # the signature of the drawn mist lobes.
1896
+ $edges = @(
1897
+ @{ x = 0; y = 0; w = $W; h = $E; g0 = $ph.g0; g1 = $ph.g1; flip = $false; m = @(0.5, 0.0, 0.5, 1.0) },
1898
+ @{ x = 0; y = ($H - $E); w = $W; h = $E; g0 = $ph.g1; g1 = $ph.g0; flip = $false; m = @(0.5, 1.0, 0.5, 0.0) },
1899
+ @{ x = 0; y = 0; w = $E; h = $H; g0 = $ph.g0; g1 = $ph.g1; flip = $true; m = @(0.0, 0.5, 1.0, 0.5) },
1900
+ @{ x = ($W - $E); y = 0; w = $E; h = $H; g0 = $ph.g0; g1 = $ph.g1; flip = $false; m = @(1.0, 0.5, 0.0, 0.5) }
1901
+ )
1902
+ $i = 0
1903
+ foreach ($b in @($script:S.bloom)) {
1904
+ if ($null -eq $b -or $i -ge $edges.Count) { break }
1905
+ $s = $edges[$i]
1906
+ $b.Fill = (New-GradH $s.g0 $s.g1 0.85 ([bool]$s.flip))
1907
+ $b.OpacityMask = (& $mask $s.m[0] $s.m[1] $s.m[2] $s.m[3] 1.0)
1908
+ $i++
1909
+ }
1910
+ # The pill's bloom is the phase accent, so it has to follow too -- otherwise a red stopped phase
1911
+ # sits in a silver halo.
1912
+ if ($null -ne $script:S.pill) {
1913
+ $glow = $script:S.pill.Effect
1914
+ if ($glow -is [System.Windows.Media.Effects.DropShadowEffect]) {
1915
+ # Effect objects are frozen once assigned, so swap in a fresh one.
1916
+ $fresh = New-Object System.Windows.Media.Effects.DropShadowEffect
1917
+ $inverse = ($script:S.pillStyle -eq 'inverse')
1918
+ if ($inverse) {
1919
+ $fresh.Color = [System.Windows.Media.Color]::FromRgb(214, 220, 228)
1920
+ $fresh.Opacity = 0.30
1921
+ } else {
1922
+ $fresh.Color = [System.Windows.Media.Color]::FromRgb([byte]$ph.base[0], [byte]$ph.base[1], [byte]$ph.base[2])
1923
+ $fresh.Opacity = 0.40
1924
+ }
1925
+ $fresh.BlurRadius = 24
1926
+ $fresh.ShadowDepth = 0
1927
+ $script:S.pill.Effect = $fresh
1928
+ }
1929
+ }
1930
+ $script:S.appliedAlpha = $null
1931
+ }
1932
+
1019
1933
  function Render-Layout {
1020
1934
  $m = $script:S.monitorBounds
1021
1935
  if ($null -eq $m) { return $false }
@@ -1024,6 +1938,24 @@ function Render-Layout {
1024
1938
  $W = [double]$m.w / $sc
1025
1939
  $H = [double]$m.h / $sc
1026
1940
  $T = [double]$CFG.ringPx / $sc
1941
+ # A repeated `show` for the same look must not rebuild the visual tree: Clear-Canvas would
1942
+ # restart every animation, which read as one hard flash per tool action. Reuse the live tree and
1943
+ # only refresh text/position; the tail and the edge breath keep their phase.
1944
+ #
1945
+ # The phase is deliberately NOT part of the key. It used to be, so acting -> stopped rebuilt the
1946
+ # whole tree and replayed Start-PillIntro's 340 ms scale-and-fade on the way out: the person saw
1947
+ # the colour turn red AND the capsule pop in again, which is the "stopped flashes twice" report.
1948
+ # A phase change is a RECOLOUR, and Set-PhaseInPlace already does that in place.
1949
+ # The smoke flag IS part of the key: turning it on or off changes which children the tree has, so
1950
+ # it is a structural change and has to rebuild. It is a rare, deliberate act (a click on the plugin
1951
+ # page), not something that happens per action, so it does not reintroduce the per-action flash.
1952
+ $layoutKey = ([string]$script:S.pillStyle) + '|' + ([string]$script:S.lookVersion) + '|' + ([string]$script:S.mistOn) + '|' + ([string]$m.x) + ',' + ([string]$m.y) + ',' + ([string]$m.w) + ',' + ([string]$m.h) + '|' + ([string]([Math]::Round($sc, 3)))
1953
+ if ($script:S.built -and $null -ne $script:S.pill -and $script:S.layoutKey -eq $layoutKey) {
1954
+ Update-PillText
1955
+ Position-Pill
1956
+ return $true
1957
+ }
1958
+ $script:S.layoutKey = $layoutKey
1027
1959
  $script:S.dipW = $W
1028
1960
  $script:S.dipH = $H
1029
1961
  $script:S.ringDip = $T
@@ -1033,20 +1965,29 @@ function Render-Layout {
1033
1965
  $ring = Build-Ring $W $H $T $ph
1034
1966
  foreach ($b in $ring.bloom) { [void]$script:S.canvas.Children.Add($b) }
1035
1967
  foreach ($b in $ring.bars) { [void]$script:S.canvas.Children.Add($b) }
1036
- [void]$script:S.canvas.Children.Add($ring.hair)
1037
1968
  $script:S.ring = $ring.bars.ToArray()
1038
1969
  $script:S.bloom = $ring.bloom.ToArray()
1039
- $script:S.outline = $ring.hair
1040
1970
  $p = Build-Pill $ph
1041
1971
  [void]$script:S.canvas.Children.Add($p.border)
1042
1972
  $script:S.pill = $p.border
1043
1973
  $script:S.pillText = $p.text
1044
1974
  $script:S.pillSub = $p.sub
1975
+ $script:S.pillOrb = $p.orb
1976
+ $script:S.pillOrbScale = $p.orbScale
1977
+ $script:S.pillOrbHalo = $p.orbHalo
1978
+ $script:S.pillOrbHaloScale = $p.orbHaloScale
1979
+ $script:S.pillBars = @($p.bars)
1980
+ $script:S.pillScale = $p.scale
1981
+ $script:S.pillBrandRun = $p.brandRun
1982
+ $script:S.pillRestRun = $p.restRun
1045
1983
  $halo = Build-Halo $ph $sc
1046
1984
  foreach ($it in $halo.items) { [void]$script:S.canvas.Children.Add($it) }
1047
1985
  $script:S.halo = $halo
1048
1986
  $script:S.haloOn = $false
1049
1987
  Update-PillText
1988
+ Start-PillIntro
1989
+ Start-PillOrb ($script:S.phase -eq 'acting' -and $script:S.pillStyle -eq 'orb')
1990
+ Start-PillBars ($script:S.phase -eq 'acting' -and $script:S.pillStyle -eq 'wave')
1050
1991
  Position-Halo
1051
1992
  return $true
1052
1993
  }
@@ -1060,11 +2001,25 @@ function CurrentPillText {
1060
2001
 
1061
2002
  function Update-PillText {
1062
2003
  if ($null -eq $script:S.pillText) { return }
1063
- $script:S.pillText.Text = (CurrentPillText)
2004
+ # The visual is two runs with a gap, no separator dot: "DSH 正在操控电脑". The API string keeps the
2005
+ # middle dot so callers and probes still read one unambiguous sentence.
2006
+ $override = [string]$script:S.textOverride
2007
+ if ($override -ne '') {
2008
+ $script:S.pillBrandRun.Text = ''
2009
+ $script:S.pillRestRun.Text = $override
2010
+ } else {
2011
+ $script:S.pillBrandRun.Text = $script:TEXT.brand
2012
+ $word = if ($script:S.phase -eq 'acting') { $script:TEXT.acting } elseif ($script:S.phase -eq 'stopped') { $script:TEXT.stopped } else { '' }
2013
+ $script:S.pillRestRun.Text = if ($word -ne '') { ' ' + $word } else { '' }
2014
+ }
1064
2015
  $sub = [string]$script:S.subtext
1065
2016
  if ($sub.Length -gt 120) { $sub = $sub.Substring(0, 120) }
1066
2017
  $script:S.pillSub.Text = $sub
1067
- if ($sub.Length -gt 0) { $script:S.pillSub.Visibility = [System.Windows.Visibility]::Visible }
2018
+ # Single line is the product: progress lives in the plugin panel, not on the capsule. Every style
2019
+ # is 44 DIP, so a second line is not a per-style capability -- it exists only for an explicit
2020
+ # textOverride, which is how a caller puts a longer message on the capsule.
2021
+ $showSub = $sub.Length -gt 0 -and $script:S.textOverride -ne ''
2022
+ if ($showSub) { $script:S.pillSub.Visibility = [System.Windows.Visibility]::Visible }
1068
2023
  else { $script:S.pillSub.Visibility = [System.Windows.Visibility]::Collapsed }
1069
2024
  Position-Pill
1070
2025
  }
@@ -1363,16 +2318,35 @@ function Update-Pulse([Int64]$now) {
1363
2318
  if ($period -le 0) { $period = 2400.0 }
1364
2319
  $elapsed = [double](($now - $script:S.phaseStartTick) / 10000.0)
1365
2320
  $frac = ($elapsed % $period) / $period
2321
+ # Smoothstep instead of raw cosine: the breath eases in and out at both ends, so the edge light
2322
+ # settles for a beat instead of reversing abruptly. Phase is preserved across repeated `show`s,
2323
+ # so a tool action never restarts the breath.
1366
2324
  $wave = 0.5 - 0.5 * [Math]::Cos($frac * 2.0 * [Math]::PI)
2325
+ $wave = $wave * $wave * (3.0 - 2.0 * $wave)
1367
2326
  $alpha = [double]$ph.lo + ([double]$ph.hi - [double]$ph.lo) * $wave
2327
+ if ($alpha -lt 0.0) { $alpha = 0.0 } elseif ($alpha -gt 1.0) { $alpha = 1.0 }
2328
+ # Phase changes reset phaseStartTick, which snaps the fresh phase's alpha to its `lo` — the
2329
+ # running ring could be at 1.0 the instant before, so the switch to stopped DIMMED the whole edge
2330
+ # 28% in one frame and then the red climbed back: the "running dies, then stopped appears"
2331
+ # disconnect. This slew limiter moves alpha toward the freshly computed target at a bounded rate
2332
+ # (full 0..1 sweep in ~150 ms at a 33 ms tick) instead of jumping, so the colour AND the breath
2333
+ # level both glide across the phase boundary. Steady-state breathing is untouched: the target
2334
+ # moves slowly enough that the limiter never clips it.
2335
+ if ($script:S.appliedAlpha -ne $null) {
2336
+ $prev = [double]$script:S.appliedAlpha
2337
+ $step = 0.22
2338
+ if ($alpha -gt $prev + $step) { $alpha = $prev + $step }
2339
+ elseif ($alpha -lt $prev - $step) { $alpha = $prev - $step }
2340
+ }
1368
2341
  $script:S.appliedAlpha = $alpha
1369
2342
  $script:S.pulseOffset = $frac
1370
2343
  $script:S.pulseAlpha = [Math]::Round($alpha, 4)
1371
2344
  foreach ($b in $script:S.ring) { if ($null -ne $b) { $b.Opacity = $alpha } }
1372
- if ($null -ne $script:S.outline) { $script:S.outline.Opacity = [Math]::Min(1.0, $alpha + 0.10) }
1373
- $bloomAlpha = $alpha * 0.55
2345
+ $bloomAlpha = $alpha * 0.72
1374
2346
  foreach ($b in $script:S.bloom) { if ($null -ne $b) { $b.Opacity = $bloomAlpha } }
1375
- if ($null -ne $script:S.pill) { $script:S.pill.Opacity = [Math]::Min(1.0, 0.84 + 0.16 * $wave) }
2347
+ foreach ($bar in @($script:S.pillBars)) {
2348
+ if ($null -ne $bar) { $bar.Opacity = 0.62 + 0.38 * $wave }
2349
+ }
1376
2350
  return $true
1377
2351
  }
1378
2352
 
@@ -1421,8 +2395,10 @@ function Set-PhaseInPlace([string]$phase) {
1421
2395
  if (-not $script:PH.ContainsKey($phase)) { Err 'bad_phase' ('unknown phase ' + (OneLine $phase)) }
1422
2396
  $changed = ([string]$script:S.phase -ne [string]$phase)
1423
2397
  $script:S.phase = $phase
1424
- $script:S.phaseStartTick = [Diagnostics.Stopwatch]::GetTimestamp()
1425
- if ($changed -and $script:S.built) { Render-Layout | Out-Null } # recolour, same HWND
2398
+ if ($changed -or -not $script:S.visible) { $script:S.phaseStartTick = [Diagnostics.Stopwatch]::GetTimestamp() }
2399
+ # A phase change is a RECOLOUR, not a rebuild. Calling Render-Layout here cleared the canvas and
2400
+ # replayed the intro animation, so the stopped state both turned red and popped in again.
2401
+ if ($changed -and $script:S.built) { Update-PhaseLook }
1426
2402
  Update-PillText
1427
2403
  $script:S.appliedAlpha = $null
1428
2404
  Update-Pulse ([Diagnostics.Stopwatch]::GetTimestamp()) | Out-Null
@@ -1510,8 +2486,9 @@ function Cmd-Show($A) {
1510
2486
  $fgBefore = (Get-Fg)
1511
2487
  $hwndBefore = [Int64]$script:S.hwnd
1512
2488
  $prevPhase = [string]$script:S.phase
2489
+ $phaseChanged = ($phase -ne $prevPhase) -or (-not $script:S.visible)
1513
2490
  $script:S.phase = $phase
1514
- $script:S.phaseStartTick = [Diagnostics.Stopwatch]::GetTimestamp()
2491
+ if ($phaseChanged) { $script:S.phaseStartTick = [Diagnostics.Stopwatch]::GetTimestamp() }
1515
2492
  Show-Overlay $m | Out-Null
1516
2493
  if ($phase -eq 'stopped') { Schedule-StoppedHide }
1517
2494
  if ($phase -eq 'hidden') { Hide-Overlay 'show asked for phase hidden' }
@@ -1538,6 +2515,7 @@ function Cmd-Show($A) {
1538
2515
  reusedHwnd = ($hwndBefore -ne 0 -and $hwndBefore -eq [Int64]$script:S.hwnd)
1539
2516
  phase = [string]$script:S.phase
1540
2517
  prevPhase = $prevPhase
2518
+ style = [string]$script:S.pillStyle
1541
2519
  text = (CurrentPillText)
1542
2520
  dpi = [int]$script:S.dpi
1543
2521
  scale = [Math]::Round([double]$script:S.scale, 4)
@@ -1550,6 +2528,9 @@ function Cmd-Show($A) {
1550
2528
  pillRect = (Get-PillRect)
1551
2529
  idleHideMs = [int]$script:S.idleHideMs
1552
2530
  hwndCreateCount = [Int64]$script:S.hwndCreateCount
2531
+ # Same counter beat/phase report: without it here, "did this show rebuild the tree?" is
2532
+ # unanswerable and a flash regression on the first command would be invisible.
2533
+ layoutBuilds = [Int64]$script:S.layoutBuilds
1553
2534
  ms = (Elapsed $t0)
1554
2535
  }
1555
2536
  }
@@ -1573,14 +2554,24 @@ function Cmd-Beat($A) {
1573
2554
  $md = ArgOf $A 'mode'
1574
2555
  if ($null -ne $md) { $script:S.mode = [string]$md }
1575
2556
  if ($null -ne $script:stoppedTimer) { try { $script:stoppedTimer.Stop() } catch { } }
2557
+ # A beat has to leave the capsule genuinely ON SCREEN, not merely "text updated".
2558
+ #
2559
+ # The bug this fixes: Show-Overlay sets $script:S.visible = $true but leaves the phase at
2560
+ # 'hidden', so the old `elseif (-not $script:S.visible)` never ran, the window was never Show()n,
2561
+ # and the text was written into an invisible tree. Any caller that sends a bare `beat` to a
2562
+ # process which has never shown anything hits this: the message is composed and never drawn.
1576
2563
  if ($script:S.phase -eq 'stopped') {
1577
2564
  Set-PhaseInPlace 'acting'
1578
- } elseif (-not $script:S.visible) {
1579
- $script:S.win.Show()
1580
- $script:S.visible = $true
1581
- Set-PhaseInPlace 'acting'
1582
- Start-RenderLoop
1583
2565
  } else {
2566
+ # Covers both "never shown" (phase hidden) and "hidden after an auto-hide".
2567
+ if (-not $script:S.visible -or $script:S.phase -eq 'hidden') {
2568
+ if (-not $script:S.visible) {
2569
+ try { $script:S.win.Show() } catch { }
2570
+ $script:S.visible = $true
2571
+ }
2572
+ Set-PhaseInPlace 'acting'
2573
+ Start-RenderLoop
2574
+ }
1584
2575
  Update-PillText
1585
2576
  }
1586
2577
  $script:S.stats.beats += 1
@@ -1593,6 +2584,8 @@ function Cmd-Beat($A) {
1593
2584
  text = (CurrentPillText)
1594
2585
  subtext = [string]$script:S.subtext
1595
2586
  framesRendered = [Int64]$script:S.framesRendered
2587
+ # The intro replay is a rebuild, so this is the number that answers "does it flash per action".
2588
+ layoutBuilds = [Int64]$script:S.layoutBuilds
1596
2589
  ms = (Elapsed $t0)
1597
2590
  }
1598
2591
  }
@@ -1733,13 +2726,55 @@ function Invoke-Request($line) {
1733
2726
  return $true
1734
2727
  }
1735
2728
  $fn = $handlers[$cmd]
1736
- # One choke point for plugin-supplied colour: every command that carries a
1737
- # palette gets it applied here, and the outcome rides back in the response so
1738
- # an unread parameter cannot pass as success.
2729
+ # One choke point for plugin-supplied look: colour and capsule style both arrive on every command
2730
+ # that carries them, are applied here, and the outcome rides back in the response so an unread
2731
+ # parameter cannot pass as success.
1739
2732
  $script:S.lastPalette = $null
2733
+ $lookDirty = $false
2734
+ $styleArg = ArgOf $A 'style'
2735
+ # ArgOf already unwraps to the bare value; the old `$styleArg.Value` read null off a string,
2736
+ # so the style argument was silently ignored and every capsule rendered as `orb`. Pinning the
2737
+ # bare form is what makes the four shapes actually selectable.
2738
+ if ($null -ne $styleArg) {
2739
+ $st = [string]$styleArg
2740
+ if (@('orb','wave','mark','inverse') -notcontains $st) {
2741
+ Send-Err $id 'bad_style' ('unknown capsule style ' + (OneLine $st))
2742
+ return $true
2743
+ }
2744
+ if ($st -ne [string]$script:S.pillStyle) { $script:S.pillStyle = $st; $lookDirty = $true }
2745
+ }
1740
2746
  if ($null -ne (ArgOf $A 'palette')) {
1741
2747
  Apply-Palette $A | Out-Null
1742
- if ($script:S.lastPalette.applied -and $script:S.built) { Render-Layout | Out-Null }
2748
+ # Only a palette that actually CHANGED the render table is a dirty look. The plugin sends the
2749
+ # palette on every show/phase/beat, so treating "palette present" as "look changed" bumped
2750
+ # lookVersion on every command, which missed the layout cache and rebuilt the tree -- replaying
2751
+ # the 340 ms intro on every single action. That is the "one flash per action" the person sees.
2752
+ # Apply-Palette already reports whether any colour landed; compare those colours with what was
2753
+ # there before to decide.
2754
+ $appliedNow = $script:S.lastPalette
2755
+ if ($appliedNow.applied) {
2756
+ $sig = (@($appliedNow.acting.g0, $appliedNow.acting.g1, $appliedNow.acting.base) -join '|')
2757
+ if ($sig -ne [string]$script:S.paletteSig) {
2758
+ $script:S.paletteSig = $sig
2759
+ $lookDirty = $true
2760
+ }
2761
+ }
2762
+ }
2763
+ # The smoke switch travels with the look on every command, like the palette and the style. Only a
2764
+ # real flip is dirty; the layout key already carries the flag, so an unchanged value costs
2765
+ # nothing.
2766
+ $mistArg = ArgOf $A 'mist'
2767
+ if ($null -ne $mistArg) {
2768
+ # BoolArg handles the JSON shapes ConvertFrom-Json produces (a real bool, or the strings
2769
+ # "true"/"1"/"yes"). Testing `-is [bool]` directly was wrong: the value arrives as a
2770
+ # PSCustomObject-wrapped scalar, so the test failed and the string compare then saw "True"
2771
+ # against "true" and pinned the flag to false.
2772
+ $wantMist = BoolArg $A 'mist' ([bool]$script:S.mistOn)
2773
+ if ($wantMist -ne [bool]$script:S.mistOn) { $script:S.mistOn = $wantMist; $lookDirty = $true }
2774
+ }
2775
+ if ($lookDirty -and $script:S.built) {
2776
+ $script:S.lookVersion += 1
2777
+ Render-Layout | Out-Null
1743
2778
  }
1744
2779
  $result = & $fn $A
1745
2780
  if ($cmd -eq 'shutdown') {
@@ -1925,4 +2960,4 @@ Log 'dispatcher returned'
1925
2960
  $exitCode = 0
1926
2961
  try { $exitCode = [int]$script:S.exitCode } catch { }
1927
2962
  Log ('exiting ' + $exitCode + ' (uptime ' + (NowMs) + ' ms, frames ' + [Int64]$script:S.framesRendered + ')')
1928
- [System.Environment]::Exit($exitCode)
2963
+ [System.Environment]::Exit($exitCode)