@oicl/openbridge-webcomponents-full-bundle 2.0.0-next.161 → 2.0.0-next.163

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 (65) hide show
  1. package/.storybook/preview.tsx +1 -1
  2. package/bundle/openbridge-webcomponents.bundle.js +439 -327
  3. package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
  4. package/custom-elements.json +134 -34
  5. package/dist/components/keyboard-numeric/keyboard-numeric.css.js +2 -3
  6. package/dist/components/keyboard-numeric/keyboard-numeric.css.js.map +1 -1
  7. package/dist/navigation-instruments/compass-sector/compass-sector.css.js +20 -11
  8. package/dist/navigation-instruments/compass-sector/compass-sector.css.js.map +1 -1
  9. package/dist/navigation-instruments/compass-sector/compass-sector.d.ts +18 -17
  10. package/dist/navigation-instruments/compass-sector/compass-sector.d.ts.map +1 -1
  11. package/dist/navigation-instruments/compass-sector/compass-sector.js +85 -52
  12. package/dist/navigation-instruments/compass-sector/compass-sector.js.map +1 -1
  13. package/dist/navigation-instruments/gauge-radial/gauge-radial.css.js +2 -6
  14. package/dist/navigation-instruments/gauge-radial/gauge-radial.css.js.map +1 -1
  15. package/dist/navigation-instruments/rudder/rudder.css.js +40 -0
  16. package/dist/navigation-instruments/rudder/rudder.css.js.map +1 -0
  17. package/dist/navigation-instruments/rudder/rudder.d.ts +9 -0
  18. package/dist/navigation-instruments/rudder/rudder.d.ts.map +1 -1
  19. package/dist/navigation-instruments/rudder/rudder.js +40 -23
  20. package/dist/navigation-instruments/rudder/rudder.js.map +1 -1
  21. package/dist/navigation-instruments/watch/watch.css.js +6 -0
  22. package/dist/navigation-instruments/watch/watch.css.js.map +1 -1
  23. package/dist/navigation-instruments/watch/watch.d.ts.map +1 -1
  24. package/dist/navigation-instruments/watch/watch.js +11 -1
  25. package/dist/navigation-instruments/watch/watch.js.map +1 -1
  26. package/dist/svghelpers/arc-frame.d.ts +8 -0
  27. package/dist/svghelpers/arc-frame.d.ts.map +1 -1
  28. package/dist/svghelpers/arc-frame.js +16 -6
  29. package/dist/svghelpers/arc-frame.js.map +1 -1
  30. package/dist/svghelpers/radial-frame.d.ts +14 -1
  31. package/dist/svghelpers/radial-frame.d.ts.map +1 -1
  32. package/dist/svghelpers/radial-frame.js +3 -1
  33. package/dist/svghelpers/radial-frame.js.map +1 -1
  34. package/docs/GettingStarted.mdx +2 -0
  35. package/docs/MigrationGuide.mdx +924 -0
  36. package/docs/migration-guide/api-ar.md +7 -0
  37. package/docs/migration-guide/api-automation.md +11 -0
  38. package/docs/migration-guide/api-building-blocks.md +4 -0
  39. package/docs/migration-guide/api-instruments.md +19 -0
  40. package/docs/migration-guide/api-ui-components.md +19 -0
  41. package/docs/migration-guide/ar-paths.md +16 -0
  42. package/docs/migration-guide/css-variables.md +13 -0
  43. package/docs/migration-guide/deprecated-components.md +6 -0
  44. package/docs/migration-guide/deprecated-members.md +8 -0
  45. package/docs/migration-guide/flash-tempo.md +5 -0
  46. package/docs/migration-guide/icons-renamed.md +6 -0
  47. package/docs/migration-guide/icons-wind.md +16 -0
  48. package/docs/migration-guide/svelte-snippets.md +8 -0
  49. package/docs/migration-guide/wind-properties.md +10 -0
  50. package/package.json +1 -1
  51. package/script/check-css-variables.ts +1 -5
  52. package/src/components/keyboard-numeric/keyboard-numeric.css +2 -3
  53. package/src/mixins/contain-aspect.css +14 -0
  54. package/src/navigation-instruments/compass-sector/compass-sector.css +17 -11
  55. package/src/navigation-instruments/compass-sector/compass-sector.spec.ts +57 -0
  56. package/src/navigation-instruments/compass-sector/compass-sector.stories.ts +23 -0
  57. package/src/navigation-instruments/compass-sector/compass-sector.ts +127 -60
  58. package/src/navigation-instruments/gauge-radial/gauge-radial.css +3 -10
  59. package/src/navigation-instruments/rudder/rudder.css +27 -0
  60. package/src/navigation-instruments/rudder/rudder.ts +52 -22
  61. package/src/navigation-instruments/watch/watch.css +6 -0
  62. package/src/navigation-instruments/watch/watch.ts +16 -1
  63. package/src/svghelpers/arc-frame.ts +19 -5
  64. package/src/svghelpers/radial-frame.spec.ts +51 -0
  65. package/src/svghelpers/radial-frame.ts +15 -1
@@ -1,5 +1,6 @@
1
1
  import {LitElement, PropertyValues, html, svg, unsafeCSS, nothing} from 'lit';
2
2
  import {property} from 'lit/decorators.js';
3
+ import {ResizeController} from '@lit-labs/observers/resize-controller.js';
3
4
  import componentStyle from './compass-sector.css?inline';
4
5
  import '../watch/watch.js';
5
6
  import {
@@ -21,12 +22,15 @@ import {
21
22
  } from '../watch/watch.js';
22
23
  import {SetpointBundle} from '../../svghelpers/setpoint-bundle.js';
23
24
  import {
24
- computeZoomToFitArcFrame,
25
- type ZoomToFitArcFrame,
26
- } from '../../svghelpers/arc-frame.js';
25
+ computeRadialFrame,
26
+ estimateLabelWidthPx,
27
+ measureContainerPx,
28
+ observeInnerBox,
29
+ type RadialFrame,
30
+ } from '../../svghelpers/radial-frame.js';
27
31
  import {ROT_ZERO_DEADBAND_DEG} from '../rate-of-turn/rot-renderer.js';
28
32
  import {customElement} from '../../decorator.js';
29
- import {normalizeAngle} from '../../svghelpers/math.js';
33
+ import {degToRad, normalizeAngle} from '../../svghelpers/math.js';
30
34
  import {InstrumentState, Priority} from '../types.js';
31
35
  export {RotType, RotPosition};
32
36
 
@@ -36,12 +40,27 @@ export enum CompassSectorPriorityElement {
36
40
  rot = 'rot',
37
41
  }
38
42
 
39
- // Fixed frame padding for the zoomed and un-zoomed paths alike. The bespoke
40
- // FOV-compression geometry stays instead of svghelpers/radial-frame.ts: the
41
- // viewBox is cached per FOV, which a container-size-dependent label reserve
42
- // would invalidate, and 72 units covers the 3-char degree labels.
43
- // TODO(#1021): adopt computeRadialFrame if degree labels ever clip.
44
- const PADDING = 72;
43
+ /** The sector instruments' shared box: 40 units around the outer ring. */
44
+ const BASE_PADDING = 48;
45
+ /**
46
+ * Bottom crops, % of the 448 box, one per feature that hangs below the band.
47
+ * Each leaves its lowest paint the same 40-unit margin the ring gets above —
48
+ * `100 · (184 − y) / 448` — and `_clipBottom()` takes the deepest in play.
49
+ * The band's own floor is the filleted inner corner at ±60°, y ≈ −47.
50
+ */
51
+ const SECTOR_CLIP_BOTTOM = 51.5;
52
+ /** ROT dots and bar ride the inner-circle track, ~5 units below the band. */
53
+ const SECTOR_CLIP_BOTTOM_ROT = 50.4;
54
+ /** Inside labels sit under the inner ring, far below the band's floor. */
55
+ const SECTOR_CLIP_BOTTOM_INSIDE_LABELS = 47.3;
56
+ /** The readout is px-sized, so it needs the room obc-gauge-radial's 180° sector reserves. */
57
+ const SECTOR_CLIP_BOTTOM_READOUT = 44;
58
+ /**
59
+ * Clearance the zoom flattens the arc out to. Zero puts the arc ends on the
60
+ * side edges, which is the point of zooming; the un-zoomed 120° arc stops
61
+ * well short of them because the box keeps the whole circle's width.
62
+ */
63
+ const SECTOR_SIDE_MARGIN = 0;
45
64
  const WATCH_TYPE = WatchCircleType.triple;
46
65
  const INNER_RADIUS = innerRingRadiusFor(WATCH_TYPE);
47
66
  /** Half of the fixed 120° arc on the watch face. */
@@ -193,13 +212,21 @@ export class ObcCompassSector extends LitElement {
193
212
  private _halfFOV = 30;
194
213
  private _arcHalfExtent = ARC_HALF_EXTENT;
195
214
  private _scale = 1;
196
- private _radiusOffset = 0;
197
- private _cachedViewBox = '';
198
- private _cachedArcFrame: ZoomToFitArcFrame | undefined;
199
215
  private _cachedAreas: WatchArea[] = [];
200
216
  private _cachedTickmarks: Tickmark[] = [];
201
217
  private _cachedAdvices: AngleAdviceRaw[] = [];
202
218
 
219
+ // The frame follows the host box, which no property change announces.
220
+ private _resizeController = new ResizeController(this, {});
221
+
222
+ private _aspectWidth = 448;
223
+ private _aspectHeight = 217.28;
224
+
225
+ override firstUpdated(changed: PropertyValues): void {
226
+ super.firstUpdated(changed);
227
+ observeInnerBox(this._resizeController, this.renderRoot);
228
+ }
229
+
203
230
  override willUpdate(changed: PropertyValues): void {
204
231
  super.willUpdate(changed);
205
232
  this._headingSp.sync({
@@ -253,7 +280,6 @@ export class ObcCompassSector extends LitElement {
253
280
  },
254
281
  ];
255
282
 
256
- this._computeViewBox();
257
283
  this._cachedTickmarks = this._buildTickmarks();
258
284
  }
259
285
 
@@ -262,6 +288,15 @@ export class ObcCompassSector extends LitElement {
262
288
  }
263
289
  }
264
290
 
291
+ override updated(changed: PropertyValues): void {
292
+ super.updated(changed);
293
+ // The host IS the canvas, so its box follows the frame the render used.
294
+ this.style.setProperty(
295
+ '--obc-compass-sector-aspect',
296
+ `${this._aspectWidth} / ${this._aspectHeight}`
297
+ );
298
+ }
299
+
265
300
  override disconnectedCallback(): void {
266
301
  super.disconnectedCallback();
267
302
  this._headingSp.dispose();
@@ -337,25 +372,57 @@ export class ObcCompassSector extends LitElement {
337
372
  // ViewBox
338
373
  // ---------------------------------------------------------------------------
339
374
 
340
- private _computeViewBox(): void {
341
- if (this.zoomToFitArc) {
342
- const targetSize = (176 + PADDING) * 2;
343
- const frame = computeZoomToFitArcFrame({
344
- areas: this._cachedAreas,
345
- outerRadius: OUTER_RING_RADIUS,
346
- innerRadius: INNER_RADIUS,
347
- extension: PADDING,
348
- targetSize,
349
- });
350
- this._radiusOffset = frame.radiusOffset;
351
- this._cachedViewBox = frame.viewBox;
352
- this._cachedArcFrame = frame;
353
- } else {
354
- this._radiusOffset = 0;
355
- const width = (176 + PADDING) * 2;
356
- this._cachedViewBox = `-${width / 2} -${width / 2} ${width} ${width}`;
357
- this._cachedArcFrame = undefined;
375
+ /** Deepest crop the active features need, so none of them is shaved. */
376
+ private _clipBottom(): number {
377
+ const clips = [SECTOR_CLIP_BOTTOM];
378
+ if (
379
+ this.rotType !== undefined &&
380
+ this.rotPosition === RotPosition.innerCircle
381
+ ) {
382
+ clips.push(SECTOR_CLIP_BOTTOM_ROT);
383
+ }
384
+ if (this.tickmarksInside) {
385
+ clips.push(SECTOR_CLIP_BOTTOM_INSIDE_LABELS);
386
+ }
387
+ if (this.hasReadout) {
388
+ clips.push(SECTOR_CLIP_BOTTOM_READOUT);
358
389
  }
390
+ return Math.min(...clips);
391
+ }
392
+
393
+ /**
394
+ * One frame per render, feeding both layers: the shared sector box cropped
395
+ * to the arc. Zoom enlarges the arc rather than the window, so the window
396
+ * only slides outward by the radius offset and the canvas holds still.
397
+ */
398
+ private _buildFrame(): RadialFrame {
399
+ const frame = computeRadialFrame({
400
+ basePadding: BASE_PADDING,
401
+ labelWidthPx: this.tickmarksInside
402
+ ? 0
403
+ : estimateLabelWidthPx(this._cachedTickmarks.map((t) => t.text)),
404
+ clips: {top: 0, bottom: this._clipBottom(), left: 0, right: 0},
405
+ containerPx: measureContainerPx(this),
406
+ });
407
+
408
+ if (!this.zoomToFitArc) {
409
+ return frame;
410
+ }
411
+
412
+ // Flatten the arc until its ends reach the same margin the 120° arc keeps,
413
+ // measured off the window rather than the live heading — a frame fitted
414
+ // where the arc currently points swings its box around the circle and the
415
+ // arc drifts with it (#1152).
416
+ const halfWidth = frame.width / 2 - SECTOR_SIDE_MARGIN;
417
+ const sin = Math.sin(degToRad(this._arcHalfExtent));
418
+ const radiusOffset = Math.max(0, halfWidth / sin - OUTER_RING_RADIUS);
419
+ const y = frame.y - radiusOffset;
420
+ return {
421
+ ...frame,
422
+ y,
423
+ radiusOffset,
424
+ viewBox: `${frame.x} ${y} ${frame.width} ${frame.height}`,
425
+ };
359
426
  }
360
427
 
361
428
  // ---------------------------------------------------------------------------
@@ -425,30 +492,18 @@ export class ObcCompassSector extends LitElement {
425
492
  }
426
493
 
427
494
  /**
428
- * Vertical placement of the readout as a percentage of the host height.
495
+ * Vertical placement of the readout as a percentage of the frame height.
429
496
  *
430
- * With `zoomToFitArc` the arc is reframed by `computeZoomToFitArcFrame`, whose
431
- * `radiusOffset`/`viewBox` depend on the arc's *absolute* orientation (which
432
- * cardinal axes its bounding box crosses), not just its bend. The arc itself
433
- * is always rotated back to the top, so it stays put on screen — but a
434
- * frame-derived offset would swing wildly as `heading` rotates the bbox around
435
- * the circle. So in zoom we use a fixed offset, which keeps the readout steady
436
- * under the (stationary) arc regardless of heading.
437
- *
438
- * Without zoom the viewBox is the fixed, origin-symmetric 120° framing, so the
439
- * geometry is orientation-independent: place the readout halfway down the inner
440
- * radius from the watch center toward the arc's inner edge.
497
+ * The anchor sits halfway down the inner radius, below the arc's inner edge.
498
+ * Zoom pushes that edge out by the radius offset, so the anchor follows it
499
+ * and the gap under the arc reads the same in both modes.
441
500
  */
442
- private get _readoutTopPercent(): number {
443
- if (this.zoomToFitArc) {
444
- return 70;
445
- }
446
- const [, vy, , vh] = this._cachedViewBox.split(' ').map(Number);
447
- if (!vh || Number.isNaN(vy)) {
501
+ private _readoutTopPercent(frame: RadialFrame): number {
502
+ if (!frame.height) {
448
503
  return 50;
449
504
  }
450
- const anchorY = -INNER_RADIUS * 0.5;
451
- return Math.round(((anchorY - vy) / vh) * 1000) / 10;
505
+ const anchorY = -INNER_RADIUS * 0.5 - frame.radiusOffset;
506
+ return Math.round(((anchorY - frame.y) / frame.height) * 1000) / 10;
452
507
  }
453
508
 
454
509
  // ---------------------------------------------------------------------------
@@ -457,8 +512,18 @@ export class ObcCompassSector extends LitElement {
457
512
 
458
513
  override render() {
459
514
  const rotation = -this.heading;
460
- const viewBox = this._cachedViewBox;
461
- const rOff = this._radiusOffset;
515
+ const frame = this._buildFrame();
516
+ const viewBox = frame.viewBox;
517
+ const rOff = frame.radiusOffset;
518
+ // The overlay rotates its element box like obc-watch does, so it needs the
519
+ // same pivot: the cropped frame's centre is not the compass centre.
520
+ const pivotX = (-frame.x / frame.width) * 100;
521
+ const pivotY = (-frame.y / frame.height) * 100;
522
+ this._aspectWidth = frame.width;
523
+ this._aspectHeight = frame.height;
524
+ const tickmarks = frame.labelsHidden
525
+ ? this._cachedTickmarks.map((t) => ({...t, text: undefined}))
526
+ : this._cachedTickmarks;
462
527
 
463
528
  const mappedCOG = this._mapAngle(this.courseOverGround);
464
529
  const mappedSetpoint =
@@ -474,17 +539,15 @@ export class ObcCompassSector extends LitElement {
474
539
  <div class="container">
475
540
  <obc-watch
476
541
  .touching=${this.touching}
477
- .padding=${PADDING}
478
542
  .advices=${this._cachedAdvices}
479
- .tickmarks=${this._cachedTickmarks}
543
+ .tickmarks=${tickmarks}
480
544
  .tickmarkStyle=${TickmarkStyle.regular}
481
545
  .tickmarksInside=${this.tickmarksInside}
482
546
  .state=${this.state}
483
547
  .watchCircleType=${WATCH_TYPE}
484
548
  .northArrow=${false}
485
549
  .areas=${this._cachedAreas}
486
- .arcFrame=${this._cachedArcFrame}
487
- .zoomToFitArc=${this.zoomToFitArc}
550
+ .arcFrame=${frame}
488
551
  .tickFadeAngle=${this._arcHalfExtent * 0.2}
489
552
  .rotation=${rotation}
490
553
  .angleSetpoint=${mappedSetpoint}
@@ -506,7 +569,11 @@ export class ObcCompassSector extends LitElement {
506
569
  .rotationsPerMinute=${this.rotationsPerMinute}
507
570
  >
508
571
  </obc-watch>
509
- <svg viewBox="${viewBox}" transform="rotate(${rotation})">
572
+ <svg
573
+ viewBox="${viewBox}"
574
+ transform="rotate(${rotation})"
575
+ style="transform-origin: ${pivotX}% ${pivotY}%"
576
+ >
510
577
  <g transform="rotate(${this.heading})">
511
578
  <line
512
579
  x1="0"
@@ -536,7 +603,7 @@ export class ObcCompassSector extends LitElement {
536
603
  this.hasReadout
537
604
  ? html`<div
538
605
  class="readout"
539
- style="top: ${this._readoutTopPercent}%"
606
+ style="top: ${this._readoutTopPercent(frame)}%"
540
607
  >
541
608
  ${renderCenterReadouts([
542
609
  {
@@ -21,16 +21,9 @@
21
21
 
22
22
  position: relative;
23
23
 
24
- /* The dial is the largest box of its sector's aspect ratio that fits inside
25
- *both* the available width and height of the (full-size) host. `width: auto`
26
- stretches the block to the host width, then `aspect-ratio` + `max-height`
27
- transfer the constraint back, shrinking it to fit a short host too — see
28
- issue #992. The host always fills its container, so the gauge can be
29
- positioned within the leftover space via the alignment classes below. */
30
- width: auto;
31
- height: auto;
32
- max-width: 100%;
33
- max-height: 100%;
24
+ /* The host always fills its container, so the gauge can be positioned within
25
+ the leftover space via the alignment classes below. */
26
+ @mixin contain-aspect;
34
27
  /* --gauge-radial-aspect is set from TS only when the frame lowered a crop
35
28
  for the label drop (frame.clipsAdjusted); otherwise the static sector
36
29
  aspect below applies. */
@@ -0,0 +1,27 @@
1
+ * {
2
+ box-sizing: border-box;
3
+ }
4
+
5
+ .container {
6
+ position: relative;
7
+ width: 100%;
8
+ height: 100%;
9
+ }
10
+
11
+ .container > * {
12
+ position: absolute;
13
+ top: 0;
14
+ left: 0;
15
+ width: 100%;
16
+ height: 100%;
17
+ }
18
+
19
+ :host {
20
+ display: block;
21
+ /* The element is the cropped canvas, not a square holding one, so the
22
+ aspect comes from the frame each render — the top crop and zoom both move
23
+ it. 448 / 269 is the un-zoomed box (448 wide × 448·(1 − 40%) tall); keep
24
+ in sync with the `clips` top in rudder.ts. */
25
+ @mixin contain-aspect;
26
+ aspect-ratio: var(--obc-rudder-aspect, 448 / 269);
27
+ }
@@ -1,5 +1,6 @@
1
- import {LitElement, PropertyValues, css, html, nothing, svg} from 'lit';
1
+ import {LitElement, PropertyValues, html, nothing, svg, unsafeCSS} from 'lit';
2
2
  import {property} from 'lit/decorators.js';
3
+ import componentStyle from './rudder.css?inline';
3
4
  import {ResizeController} from '@lit-labs/observers/resize-controller.js';
4
5
  import '../watch/watch.js';
5
6
  import {Tickmark, TickmarkStyle, TickmarkType} from '../watch/tickmark.js';
@@ -8,6 +9,8 @@ import {InstrumentState, Priority} from '../types.js';
8
9
  import {SetpointMixin} from '../../svghelpers/setpoint-mixin.js';
9
10
  import {AdviceState, AngleAdvice, AngleAdviceRaw} from '../watch/advice.js';
10
11
  import {customElement} from '../../decorator.js';
12
+ import {degToRad} from '../../svghelpers/math.js';
13
+ import {ArcFrameFit} from '../../svghelpers/arc-frame.js';
11
14
  import {
12
15
  applyPinnedHostSize,
13
16
  computeRadialFrame,
@@ -120,6 +123,14 @@ export class ObcRudder extends SetpointMixin(LitElement) {
120
123
 
121
124
  override updated(changed: PropertyValues): void {
122
125
  super.updated(changed);
126
+ // The host IS the canvas, so its box follows the frame the render used.
127
+ const frame = this._frame;
128
+ if (frame) {
129
+ this.style.setProperty(
130
+ '--obc-rudder-aspect',
131
+ `${frame.width} / ${frame.height}`
132
+ );
133
+ }
123
134
  this._hostSizePinned = applyPinnedHostSize(
124
135
  this,
125
136
  this._frame,
@@ -127,6 +138,32 @@ export class ObcRudder extends SetpointMixin(LitElement) {
127
138
  );
128
139
  }
129
140
 
141
+ /**
142
+ * Radial reach of the needle path about the watch centre, and its half
143
+ * width — the zoomed arc's own box stops short of the inner end.
144
+ */
145
+ private static readonly NEEDLE_INNER_RADIUS = -16.5;
146
+ private static readonly NEEDLE_OUTER_RADIUS = 160.65;
147
+ private static readonly NEEDLE_HALF_WIDTH = 16.5;
148
+
149
+ /** Box the zoomed frame must keep visible, in SVG units. */
150
+ private _needleIncludeBox(radiusOffset: number) {
151
+ if (this.variant !== ObcRudderVariant.Needle) {
152
+ return undefined;
153
+ }
154
+ const rad = degToRad(this.getAngle(this.angle));
155
+ const u = {x: Math.sin(rad), y: -Math.cos(rad)};
156
+ const inner = ObcRudder.NEEDLE_INNER_RADIUS + radiusOffset;
157
+ const outer = ObcRudder.NEEDLE_OUTER_RADIUS + radiusOffset;
158
+ const w = ObcRudder.NEEDLE_HALF_WIDTH;
159
+ return {
160
+ xMin: Math.min(inner * u.x, outer * u.x) - w,
161
+ xMax: Math.max(inner * u.x, outer * u.x) + w,
162
+ yMin: Math.min(inner * u.y, outer * u.y) - w,
163
+ yMax: Math.max(inner * u.y, outer * u.y) + w,
164
+ };
165
+ }
166
+
130
167
  private get _needleTransform(): string {
131
168
  const rOff = this._radiusOffset;
132
169
  if (rOff > 0) {
@@ -271,7 +308,7 @@ export class ObcRudder extends SetpointMixin(LitElement) {
271
308
  };
272
309
  });
273
310
 
274
- const frame = computeRadialFrame({
311
+ const frameOptions = {
275
312
  basePadding: 48,
276
313
  labelWidthPx: this.tickmarksInside
277
314
  ? 0
@@ -282,9 +319,20 @@ export class ObcRudder extends SetpointMixin(LitElement) {
282
319
  containerPx: measureContainerPx(this),
283
320
  faceDiameter: this.faceDiameter,
284
321
  zoomToFitArc: this.zoomToFitArc,
322
+ // The zoomed arc is flat; a square box would be mostly empty height.
323
+ zoomFit: ArcFrameFit.bbox,
285
324
  areas,
286
325
  innerRadius: innerRingRadiusFor(WatchCircleType.double),
287
- });
326
+ };
327
+ // `includeBox` never feeds the radius search, so the offset the first pass
328
+ // returns is the one the needle box is drawn against.
329
+ const probe = computeRadialFrame(frameOptions);
330
+ const zoomIncludeBox = this.zoomToFitArc
331
+ ? this._needleIncludeBox(probe.radiusOffset)
332
+ : undefined;
333
+ const frame = zoomIncludeBox
334
+ ? computeRadialFrame({...frameOptions, zoomIncludeBox})
335
+ : probe;
288
336
  this._radiusOffset = frame.radiusOffset;
289
337
  this._frame = frame;
290
338
  const shownTickmarks = frame.labelsHidden
@@ -320,25 +368,7 @@ export class ObcRudder extends SetpointMixin(LitElement) {
320
368
  `;
321
369
  }
322
370
 
323
- static override styles = css`
324
- * {
325
- box-sizing: border-box;
326
- }
327
-
328
- .container {
329
- position: relative;
330
- width: 100%;
331
- height: 100%;
332
- }
333
-
334
- .container > * {
335
- position: absolute;
336
- top: 0;
337
- left: 0;
338
- width: 100%;
339
- height: 100%;
340
- }
341
- `;
371
+ static override styles = unsafeCSS(componentStyle);
342
372
  }
343
373
 
344
374
  declare global {
@@ -10,6 +10,12 @@ svg {
10
10
  display: block;
11
11
  }
12
12
 
13
+ svg.cropped {
14
+ /* A cropped frame paints its arc outside the viewBox before `rotation`
15
+ swings it into view; the host's overflow rule is what clips. */
16
+ overflow: visible;
17
+ }
18
+
13
19
  .label {
14
20
  @mixin font-body;
15
21
  font-size: calc(12px / var(--scale, 1));
@@ -994,6 +994,8 @@ export class ObcWatch extends LitElement {
994
994
  override render() {
995
995
  let width: number;
996
996
  let height: number;
997
+ let frameX: number;
998
+ let frameY: number;
997
999
  let viewBox: string;
998
1000
 
999
1001
  if (this.arcFrame) {
@@ -1002,6 +1004,8 @@ export class ObcWatch extends LitElement {
1002
1004
  this._ownFrame = undefined;
1003
1005
  width = this.arcFrame.width;
1004
1006
  height = this.arcFrame.height;
1007
+ frameX = this.arcFrame.x;
1008
+ frameY = this.arcFrame.y;
1005
1009
  viewBox = this.arcFrame.viewBox;
1006
1010
  } else {
1007
1011
  const frame = computeRadialFrame({
@@ -1024,11 +1028,21 @@ export class ObcWatch extends LitElement {
1024
1028
  this._ownFrame = frame;
1025
1029
  width = frame.width;
1026
1030
  height = frame.height;
1031
+ frameX = frame.x;
1032
+ frameY = frame.y;
1027
1033
  viewBox = frame.viewBox;
1028
1034
  }
1029
1035
 
1030
1036
  const rOff = this._rOff;
1031
1037
  const scale = this.getScale({width, height});
1038
+ // `rotation` turns the element box, which pivots on the box centre — the
1039
+ // watch centre only while the frame is origin-centred. A cropped frame
1040
+ // (sector window) moves it, so pin the pivot to the SVG origin instead.
1041
+ const pivotX = width > 0 ? (-frameX / width) * 100 : 50;
1042
+ const pivotY = height > 0 ? (-frameY / height) * 100 : 50;
1043
+ // A cropped frame paints beyond the viewBox, which the viewport would cut
1044
+ // before the rotation brings it into view. Only those need the escape.
1045
+ const cropped = pivotX !== 50 || pivotY !== 50;
1032
1046
  const angleSetpoint = this.renderSetpoint();
1033
1047
  // Route through _bandRadius so inside labels track the (zoom-shifted) inner
1034
1048
  // band edge; the coupling is intentional (see _bandRadius INVARIANT).
@@ -1122,10 +1136,11 @@ export class ObcWatch extends LitElement {
1122
1136
  : nothing;
1123
1137
  return html`
1124
1138
  <svg
1139
+ class=${cropped ? 'cropped' : nothing}
1125
1140
  width="100%"
1126
1141
  height="100%"
1127
1142
  viewBox=${viewBox}
1128
- style="--scale: ${scale}"
1143
+ style="--scale: ${scale}; transform-origin: ${pivotX}% ${pivotY}%"
1129
1144
  transform="rotate(${this.rotation ?? 0})"
1130
1145
  >
1131
1146
  ${this.watchCircle()} ${this.renderBars()}
@@ -13,6 +13,14 @@ export interface ZoomToFitArcFrame extends ArcViewBox {
13
13
  radiusOffset: number;
14
14
  }
15
15
 
16
+ /** Shape of the zoom viewBox. */
17
+ export enum ArcFrameFit {
18
+ /** Square around the arc — what instruments with a round face expect. */
19
+ square = 'square',
20
+ /** The arc's own bounding box, which crops a flat arc's empty height. */
21
+ bbox = 'bbox',
22
+ }
23
+
16
24
  /**
17
25
  * Normalize a user-supplied watch-arc half-extent (in degrees) to a finite
18
26
  * value clamped into a sane range. Guards against `NaN`/`Infinity` produced
@@ -68,6 +76,7 @@ export function computeZoomToFitArcFrame(options: {
68
76
  targetSize: number;
69
77
  margin?: number;
70
78
  includeBox?: {xMin: number; yMin: number; xMax: number; yMax: number};
79
+ fit?: ArcFrameFit;
71
80
  }): ZoomToFitArcFrame {
72
81
  const {
73
82
  areas,
@@ -77,6 +86,7 @@ export function computeZoomToFitArcFrame(options: {
77
86
  targetSize,
78
87
  margin = 0.06,
79
88
  includeBox,
89
+ fit = ArcFrameFit.square,
80
90
  } = options;
81
91
 
82
92
  if (areas.length === 0) {
@@ -139,15 +149,19 @@ export function computeZoomToFitArcFrame(options: {
139
149
  const rawW = bbox.xMax - bbox.xMin;
140
150
  const rawH = bbox.yMax - bbox.yMin;
141
151
  const side = Math.max(rawW, rawH);
142
- const padded = side * (1 + margin * 2);
152
+ const pad = side * margin;
143
153
 
144
154
  const cx = (bbox.xMin + bbox.xMax) / 2;
145
155
  const cy = (bbox.yMin + bbox.yMax) / 2;
146
156
 
147
- const x = round4(cx - padded / 2);
148
- const y = round4(cy - padded / 2);
149
- const w = round4(padded);
150
- const h = round4(padded);
157
+ // 'bbox' hugs the arc; a flat arc in a square box is mostly empty.
158
+ const boxW = fit === ArcFrameFit.bbox ? rawW + pad * 2 : side + pad * 2;
159
+ const boxH = fit === ArcFrameFit.bbox ? rawH + pad * 2 : side + pad * 2;
160
+
161
+ const x = round4(cx - boxW / 2);
162
+ const y = round4(cy - boxH / 2);
163
+ const w = round4(boxW);
164
+ const h = round4(boxH);
151
165
 
152
166
  return {
153
167
  radiusOffset,
@@ -294,6 +294,57 @@ describe('computeRadialFrame — zoom path', () => {
294
294
  });
295
295
  });
296
296
 
297
+ describe('computeRadialFrame — sector crop (compass-sector)', () => {
298
+ const SECTOR_CLIP = {top: 0, bottom: 51.5, left: 0, right: 0};
299
+
300
+ it('crops the bottom to a wide canvas and leaves the clips alone', () => {
301
+ const f = computeRadialFrame({basePadding: 48, clips: SECTOR_CLIP});
302
+ expect(f.x).toBe(-224);
303
+ expect(f.y).toBe(-224);
304
+ expect(f.width).toBe(448);
305
+ expect(f.height).toBeCloseTo(217.28, 2);
306
+ // A static aspect-ratio on the host is only safe while this stays false.
307
+ expect(f.clipsAdjusted).toBe(false);
308
+ });
309
+
310
+ it('keeps the aspect constant as the label reserve grows the box', () => {
311
+ const labelWidthPx = estimateLabelWidthPx(['330']);
312
+ const aspects = [600, 400, 200].map((px) => {
313
+ const f = computeRadialFrame({
314
+ basePadding: 48,
315
+ labelWidthPx,
316
+ clips: SECTOR_CLIP,
317
+ containerPx: {width: px, height: px},
318
+ });
319
+ return f.width / f.height;
320
+ });
321
+ for (const aspect of aspects) {
322
+ expect(aspect).toBeCloseTo(aspects[0], 10);
323
+ }
324
+ });
325
+
326
+ it('fits the zoomed arc inside the cropped window at every field of view', () => {
327
+ const frame = computeRadialFrame({basePadding: 48, clips: SECTOR_CLIP});
328
+ const OUTER = 184;
329
+ const INNER = 88;
330
+ const SIDE_MARGIN = 32;
331
+
332
+ for (const halfExtent of [5, 15, 30, 45, 60]) {
333
+ const rad = (halfExtent * Math.PI) / 180;
334
+ // compass-sector flattens the arc until its ends reach SIDE_MARGIN.
335
+ const halfWidth = frame.width / 2 - SIDE_MARGIN;
336
+ const radiusOffset = Math.max(0, halfWidth / Math.sin(rad) - OUTER);
337
+ const ends = (OUTER + radiusOffset) * Math.sin(rad);
338
+ // Top of the ring down to the arc ends' inner corners.
339
+ const height =
340
+ OUTER + radiusOffset - (INNER + radiusOffset) * Math.cos(rad);
341
+
342
+ expect(ends).toBeLessThanOrEqual(frame.width / 2);
343
+ expect(height).toBeLessThanOrEqual(frame.height);
344
+ }
345
+ });
346
+ });
347
+
297
348
  describe('estimateLabelWidthPx', () => {
298
349
  it('is maxChars * 7', () => {
299
350
  expect(estimateLabelWidthPx(['0', '3600', undefined])).toBe(28);
@@ -1,5 +1,9 @@
1
1
  import type {WatchArea} from '../navigation-instruments/watch/watch.js';
2
- import {computeZoomToFitArcFrame, type ZoomToFitArcFrame} from './arc-frame.js';
2
+ import {
3
+ computeZoomToFitArcFrame,
4
+ ArcFrameFit,
5
+ type ZoomToFitArcFrame,
6
+ } from './arc-frame.js';
3
7
 
4
8
  /**
5
9
  * Shared frame computation for circular/radial watch-based instruments.
@@ -122,6 +126,14 @@ export interface RadialFrameOptions {
122
126
  areas?: WatchArea[];
123
127
  /** Innermost visible radius (depends on WatchCircleType); zoom path only. */
124
128
  innerRadius?: number;
129
+ /** Zoom viewBox shape; `bbox` crops a flat arc's empty height. */
130
+ zoomFit?: ArcFrameFit;
131
+ /**
132
+ * Region that must stay inside the zoomed viewBox — an overlay the arc's own
133
+ * box would leave out, such as a needle reaching in toward the centre. It
134
+ * widens the final box only; the arc still grows freely.
135
+ */
136
+ zoomIncludeBox?: {xMin: number; yMin: number; xMax: number; yMax: number};
125
137
  }
126
138
 
127
139
  export interface RadialFrame extends ZoomToFitArcFrame {
@@ -484,6 +496,8 @@ function zoomFrameAt(
484
496
  innerRadius: opts.innerRadius ?? OUTER_RING_RADIUS,
485
497
  extension,
486
498
  targetSize: (RADIAL_VIEWBOX_BASE + extension) * 2,
499
+ fit: opts.zoomFit,
500
+ includeBox: opts.zoomIncludeBox,
487
501
  });
488
502
  }
489
503