@oicl/openbridge-webcomponents-full-bundle 2.1.0-next.6 → 2.1.0-next.7

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 (30) hide show
  1. package/.storybook/vitest.hidden-mount.setup.ts +96 -0
  2. package/bundle/openbridge-webcomponents.bundle.js +47 -8
  3. package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
  4. package/custom-elements.json +65 -3
  5. package/dist/ar/chart-object-vessel-button/chart-object-vessel-button.d.ts.map +1 -1
  6. package/dist/ar/chart-object-vessel-button/chart-object-vessel-button.js +1 -1
  7. package/dist/ar/chart-object-vessel-button/chart-object-vessel-button.js.map +1 -1
  8. package/dist/building-blocks/chart-line/chart-line-base.css.js +8 -0
  9. package/dist/building-blocks/chart-line/chart-line-base.css.js.map +1 -1
  10. package/dist/building-blocks/chart-line/chart-line-base.d.ts +3 -1
  11. package/dist/building-blocks/chart-line/chart-line-base.d.ts.map +1 -1
  12. package/dist/building-blocks/chart-line/chart-line-base.js +9 -4
  13. package/dist/building-blocks/chart-line/chart-line-base.js.map +1 -1
  14. package/dist/charthelpers/label-threshold.d.ts +7 -2
  15. package/dist/charthelpers/label-threshold.d.ts.map +1 -1
  16. package/dist/charthelpers/label-threshold.js +14 -2
  17. package/dist/charthelpers/label-threshold.js.map +1 -1
  18. package/dist/navigation-instruments/watch-flat/watch-flat.d.ts +8 -0
  19. package/dist/navigation-instruments/watch-flat/watch-flat.d.ts.map +1 -1
  20. package/dist/navigation-instruments/watch-flat/watch-flat.js +17 -1
  21. package/dist/navigation-instruments/watch-flat/watch-flat.js.map +1 -1
  22. package/package.json +2 -1
  23. package/src/ar/chart-object-vessel-button/chart-object-vessel-button.ts +3 -1
  24. package/src/building-blocks/chart-line/chart-line-base.css +8 -0
  25. package/src/building-blocks/chart-line/chart-line-base.ts +16 -5
  26. package/src/charthelpers/label-threshold.spec.ts +28 -0
  27. package/src/charthelpers/label-threshold.ts +16 -3
  28. package/src/navigation-instruments/rot-linear/rot-linear.spec.ts +36 -0
  29. package/src/navigation-instruments/watch-flat/watch-flat.spec.ts +76 -0
  30. package/src/navigation-instruments/watch-flat/watch-flat.ts +22 -1
@@ -1,6 +1,6 @@
1
1
  /** What a chart does when its canvas is resized. */
2
2
  export interface LabelThresholdCallbacks {
3
- /** The resize crossed the threshold. */
3
+ /** The resize crossed the threshold, or gave the canvas its first size. */
4
4
  rebuild(): void;
5
5
  /** The resize stayed on one side of it. */
6
6
  update(): void;
@@ -11,9 +11,14 @@ export interface LabelThresholdCallbacks {
11
11
  * therefore needs a rebuild, while every other resize is an in-place
12
12
  * update. This owns the which-side state; the chart owns the decision.
13
13
  *
14
+ * A chart created while its canvas had no size (in a hidden container) is
15
+ * also rebuilt once, when the canvas first gets one: Chart.js keeps layout
16
+ * state from that empty first pass, and a resize leaves the plot a pixel off
17
+ * a chart created at its real size.
18
+ *
14
19
  * @param target - The chart's canvas. A detached target is ignored: it has no size and no chart to serve.
15
20
  * @param isAboveThreshold - The chart's own test, read once now and after every resize.
16
- * @param callbacks - `rebuild` on a crossing, `update` otherwise.
21
+ * @param callbacks - `rebuild` on a crossing or a first size, `update` otherwise.
17
22
  * @returns The observer, for the chart to disconnect in `disconnectedCallback`.
18
23
  */
19
24
  export declare function observeLabelThreshold(target: Element, isAboveThreshold: () => boolean, callbacks: LabelThresholdCallbacks): ResizeObserver;
@@ -1 +1 @@
1
- {"version":3,"file":"label-threshold.d.ts","sourceRoot":"","sources":["../../src/charthelpers/label-threshold.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,MAAM,WAAW,uBAAuB;IACtC,wCAAwC;IACxC,OAAO,IAAI,IAAI,CAAC;IAChB,2CAA2C;IAC3C,MAAM,IAAI,IAAI,CAAC;CAChB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,OAAO,EACf,gBAAgB,EAAE,MAAM,OAAO,EAC/B,SAAS,EAAE,uBAAuB,GACjC,cAAc,CAehB"}
1
+ {"version":3,"file":"label-threshold.d.ts","sourceRoot":"","sources":["../../src/charthelpers/label-threshold.ts"],"names":[],"mappings":"AAKA,oDAAoD;AACpD,MAAM,WAAW,uBAAuB;IACtC,2EAA2E;IAC3E,OAAO,IAAI,IAAI,CAAC;IAChB,2CAA2C;IAC3C,MAAM,IAAI,IAAI,CAAC;CAChB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,OAAO,EACf,gBAAgB,EAAE,MAAM,OAAO,EAC/B,SAAS,EAAE,uBAAuB,GACjC,cAAc,CAkBhB"}
@@ -1,23 +1,35 @@
1
1
  //#region src/charthelpers/label-threshold.ts
2
+ function hasSize(target) {
3
+ const { width, height } = target.getBoundingClientRect();
4
+ return width > 0 && height > 0;
5
+ }
2
6
  /**
3
7
  * A chart installs its label plugins at creation time, from which side of
4
8
  * the label threshold the canvas is on. A resize that crosses the threshold
5
9
  * therefore needs a rebuild, while every other resize is an in-place
6
10
  * update. This owns the which-side state; the chart owns the decision.
7
11
  *
12
+ * A chart created while its canvas had no size (in a hidden container) is
13
+ * also rebuilt once, when the canvas first gets one: Chart.js keeps layout
14
+ * state from that empty first pass, and a resize leaves the plot a pixel off
15
+ * a chart created at its real size.
16
+ *
8
17
  * @param target - The chart's canvas. A detached target is ignored: it has no size and no chart to serve.
9
18
  * @param isAboveThreshold - The chart's own test, read once now and after every resize.
10
- * @param callbacks - `rebuild` on a crossing, `update` otherwise.
19
+ * @param callbacks - `rebuild` on a crossing or a first size, `update` otherwise.
11
20
  * @returns The observer, for the chart to disconnect in `disconnectedCallback`.
12
21
  */
13
22
  function observeLabelThreshold(target, isAboveThreshold, callbacks) {
14
23
  let wasAbove = isAboveThreshold();
24
+ let hadSize = hasSize(target);
15
25
  const observer = new ResizeObserver(() => {
16
26
  if (!target.isConnected) return;
17
27
  const isAbove = isAboveThreshold();
18
28
  const crossed = isAbove !== wasAbove;
19
29
  wasAbove = isAbove;
20
- if (crossed) callbacks.rebuild();
30
+ const gotSize = !hadSize && hasSize(target);
31
+ hadSize = hasSize(target);
32
+ if (crossed || gotSize) callbacks.rebuild();
21
33
  else callbacks.update();
22
34
  });
23
35
  observer.observe(target);
@@ -1 +1 @@
1
- {"version":3,"file":"label-threshold.js","names":[],"sources":["../../src/charthelpers/label-threshold.ts"],"sourcesContent":["/** What a chart does when its canvas is resized. */\nexport interface LabelThresholdCallbacks {\n /** The resize crossed the threshold. */\n rebuild(): void;\n /** The resize stayed on one side of it. */\n update(): void;\n}\n\n/**\n * A chart installs its label plugins at creation time, from which side of\n * the label threshold the canvas is on. A resize that crosses the threshold\n * therefore needs a rebuild, while every other resize is an in-place\n * update. This owns the which-side state; the chart owns the decision.\n *\n * @param target - The chart's canvas. A detached target is ignored: it has no size and no chart to serve.\n * @param isAboveThreshold - The chart's own test, read once now and after every resize.\n * @param callbacks - `rebuild` on a crossing, `update` otherwise.\n * @returns The observer, for the chart to disconnect in `disconnectedCallback`.\n */\nexport function observeLabelThreshold(\n target: Element,\n isAboveThreshold: () => boolean,\n callbacks: LabelThresholdCallbacks\n): ResizeObserver {\n let wasAbove = isAboveThreshold();\n const observer = new ResizeObserver(() => {\n if (!target.isConnected) return;\n const isAbove = isAboveThreshold();\n const crossed = isAbove !== wasAbove;\n wasAbove = isAbove;\n if (crossed) {\n callbacks.rebuild();\n } else {\n callbacks.update();\n }\n });\n observer.observe(target);\n return observer;\n}\n"],"mappings":";;;;;;;;;;;;AAmBA,SAAgB,sBACd,QACA,kBACA,WACgB;CAChB,IAAI,WAAW,iBAAiB;CAChC,MAAM,WAAW,IAAI,qBAAqB;EACxC,IAAI,CAAC,OAAO,aAAa;EACzB,MAAM,UAAU,iBAAiB;EACjC,MAAM,UAAU,YAAY;EAC5B,WAAW;EACX,IAAI,SACF,UAAU,QAAQ;OAElB,UAAU,OAAO;CAErB,CAAC;CACD,SAAS,QAAQ,MAAM;CACvB,OAAO;AACT"}
1
+ {"version":3,"file":"label-threshold.js","names":[],"sources":["../../src/charthelpers/label-threshold.ts"],"sourcesContent":["function hasSize(target: Element): boolean {\n const {width, height} = target.getBoundingClientRect();\n return width > 0 && height > 0;\n}\n\n/** What a chart does when its canvas is resized. */\nexport interface LabelThresholdCallbacks {\n /** The resize crossed the threshold, or gave the canvas its first size. */\n rebuild(): void;\n /** The resize stayed on one side of it. */\n update(): void;\n}\n\n/**\n * A chart installs its label plugins at creation time, from which side of\n * the label threshold the canvas is on. A resize that crosses the threshold\n * therefore needs a rebuild, while every other resize is an in-place\n * update. This owns the which-side state; the chart owns the decision.\n *\n * A chart created while its canvas had no size (in a hidden container) is\n * also rebuilt once, when the canvas first gets one: Chart.js keeps layout\n * state from that empty first pass, and a resize leaves the plot a pixel off\n * a chart created at its real size.\n *\n * @param target - The chart's canvas. A detached target is ignored: it has no size and no chart to serve.\n * @param isAboveThreshold - The chart's own test, read once now and after every resize.\n * @param callbacks - `rebuild` on a crossing or a first size, `update` otherwise.\n * @returns The observer, for the chart to disconnect in `disconnectedCallback`.\n */\nexport function observeLabelThreshold(\n target: Element,\n isAboveThreshold: () => boolean,\n callbacks: LabelThresholdCallbacks\n): ResizeObserver {\n let wasAbove = isAboveThreshold();\n let hadSize = hasSize(target);\n const observer = new ResizeObserver(() => {\n if (!target.isConnected) return;\n const isAbove = isAboveThreshold();\n const crossed = isAbove !== wasAbove;\n wasAbove = isAbove;\n const gotSize = !hadSize && hasSize(target);\n hadSize = hasSize(target);\n if (crossed || gotSize) {\n callbacks.rebuild();\n } else {\n callbacks.update();\n }\n });\n observer.observe(target);\n return observer;\n}\n"],"mappings":";AAAA,SAAS,QAAQ,QAA0B;CACzC,MAAM,EAAC,OAAO,WAAU,OAAO,sBAAsB;CACrD,OAAO,QAAQ,KAAK,SAAS;AAC/B;;;;;;;;;;;;;;;;;AA0BA,SAAgB,sBACd,QACA,kBACA,WACgB;CAChB,IAAI,WAAW,iBAAiB;CAChC,IAAI,UAAU,QAAQ,MAAM;CAC5B,MAAM,WAAW,IAAI,qBAAqB;EACxC,IAAI,CAAC,OAAO,aAAa;EACzB,MAAM,UAAU,iBAAiB;EACjC,MAAM,UAAU,YAAY;EAC5B,WAAW;EACX,MAAM,UAAU,CAAC,WAAW,QAAQ,MAAM;EAC1C,UAAU,QAAQ,MAAM;EACxB,IAAI,WAAW,SACb,UAAU,QAAQ;OAElB,UAAU,OAAO;CAErB,CAAC;CACD,SAAS,QAAQ,MAAM;CACvB,OAAO;AACT"}
@@ -76,7 +76,14 @@ export declare class ObcWatchFlat extends LitElement {
76
76
  get rotationsPerMinute(): number;
77
77
  private _legacyRotationsPerMinute;
78
78
  private _rotController?;
79
+ private _resizeController;
79
80
  private get _effectiveRpm();
81
+ /**
82
+ * Rendered px per user-space unit; the labels divide by it to keep their
83
+ * on-screen size. 1:1 while the strip has no width yet (hidden, or not laid
84
+ * out), until the ResizeController re-renders it.
85
+ */
86
+ private scaleFor;
80
87
  private get totalHeight();
81
88
  private renderClipPath;
82
89
  private renderLabelMask;
@@ -89,6 +96,7 @@ export declare class ObcWatchFlat extends LitElement {
89
96
  private getRotTrackY;
90
97
  private getRotColors;
91
98
  private renderRot;
99
+ firstUpdated(changed: PropertyValues): void;
92
100
  updated(changed: PropertyValues): void;
93
101
  disconnectedCallback(): void;
94
102
  render(): import('lit-html').TemplateResult<1>;
@@ -1 +1 @@
1
- {"version":3,"file":"watch-flat.d.ts","sourceRoot":"","sources":["../../../src/navigation-instruments/watch-flat/watch-flat.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,cAAc,EACd,iBAAiB,EAKlB,MAAM,KAAK,CAAC;AAGb,OAAO,EAAC,QAAQ,EAA0B,MAAM,oBAAoB,CAAC;AAErE,OAAO,EAAC,KAAK,EAAC,MAAM,iCAAiC,CAAC;AAEtD,OAAO,EAAC,QAAQ,EAAC,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,OAAO,EACP,iBAAiB,EAQlB,MAAM,iCAAiC,CAAC;AAMzC,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CAAC,cAAc;IAUtB,OAAO,CAAC,eAAe;IAqBvB,OAAO,CAAC,YAAY;IAgBpB,OAAO,CAAC,SAAS;IAyDjB,oDAAoD;IACpD,OAAO,KAAK,UAAU,GAMrB;IAED,OAAO,CAAC,cAAc;IAiBtB,OAAO,CAAC,iBAAiB;IA0BzB,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,YAAY;IAsCpB,OAAO,CAAC,SAAS;IA0DR,YAAY,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IAK3C,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IAkCtC,oBAAoB,IAAI,IAAI;IAK5B,MAAM;IAgDf,OAAgB,MAAM,0BAA2B;CAClD;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,gBAAgB,EAAE,YAAY,CAAC;KAChC;CACF"}
@@ -1,6 +1,7 @@
1
1
  import { customElement } from "../../decorator.js";
2
2
  import __decorate from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/decorate.js";
3
3
  import { Priority } from "../types.js";
4
+ import { measureContainerPx, observeInnerBox } from "../../svghelpers/radial-frame.js";
4
5
  import { rect } from "../../svghelpers/rectangular.js";
5
6
  import { LinearRotPosition, ROT_ZERO_DEADBAND_PX, RotType, renderLinearRotBarDots, renderLinearRotBarStatic, renderLinearRotDots, renderLinearRotZeroPill } from "../rate-of-turn/rot-renderer.js";
6
7
  import { RateOfTurnController, disposeRotController } from "../rate-of-turn/rate-of-turn.controller.js";
@@ -8,6 +9,7 @@ import { TickmarkStyle, tickmark } from "./tickmark-flat.js";
8
9
  import watch_flat_default from "./watch-flat.css.js";
9
10
  import { LitElement, html, nothing, svg, unsafeCSS } from "lit";
10
11
  import { property } from "lit/decorators.js";
12
+ import { ResizeController } from "@lit-labs/observers/resize-controller.js";
11
13
  //#region src/navigation-instruments/watch-flat/watch-flat.ts
12
14
  var ObcWatchFlat = class ObcWatchFlat extends LitElement {
13
15
  constructor(..._args) {
@@ -35,6 +37,7 @@ var ObcWatchFlat = class ObcWatchFlat extends LitElement {
35
37
  this.rotAtZeroDeadband = ROT_ZERO_DEADBAND_PX;
36
38
  this.rotDotAnimationFactor = 18;
37
39
  this._legacyRotationsPerMinute = 0;
40
+ this._resizeController = new ResizeController(this, {});
38
41
  }
39
42
  /**
40
43
  * @deprecated Use `rateOfTurnDegreesPerMinute` (and optionally
@@ -51,6 +54,15 @@ var ObcWatchFlat = class ObcWatchFlat extends LitElement {
51
54
  if (this.rateOfTurnDegreesPerMinute != null) return this.rateOfTurnDegreesPerMinute / 360 * this.rotDotAnimationFactor;
52
55
  return this._legacyRotationsPerMinute;
53
56
  }
57
+ /**
58
+ * Rendered px per user-space unit; the labels divide by it to keep their
59
+ * on-screen size. 1:1 while the strip has no width yet (hidden, or not laid
60
+ * out), until the ResizeController re-renders it.
61
+ */
62
+ scaleFor(viewBoxWidth) {
63
+ const scale = measureContainerPx(this).width / viewBoxWidth;
64
+ return Number.isFinite(scale) && scale > 0 ? scale : 1;
65
+ }
54
66
  get totalHeight() {
55
67
  return this.bottomBar ? this.height + this.ticksHeight : this.height;
56
68
  }
@@ -234,6 +246,10 @@ var ObcWatchFlat = class ObcWatchFlat extends LitElement {
234
246
  </g>
235
247
  ` : nothing;
236
248
  }
249
+ firstUpdated(changed) {
250
+ super.firstUpdated(changed);
251
+ observeInnerBox(this._resizeController, this.renderRoot);
252
+ }
237
253
  updated(changed) {
238
254
  super.updated(changed);
239
255
  const el = this.rotType ? this.renderRoot.querySelector("#rot-spinner") : null;
@@ -256,7 +272,7 @@ var ObcWatchFlat = class ObcWatchFlat extends LitElement {
256
272
  const width = (this.width / 2 + this.padding) * 2;
257
273
  const th = this.totalHeight;
258
274
  const viewBox = `-${width / 2} -${th / 2} ${width} ${th}`;
259
- const scale = this.clientWidth / width;
275
+ const scale = this.scaleFor(width);
260
276
  const contentOffsetY = this.bottomBar ? -this.ticksHeight / 2 : 0;
261
277
  return html`
262
278
  <svg
@@ -1 +1 @@
1
- {"version":3,"file":"watch-flat.js","names":[],"sources":["../../../src/navigation-instruments/watch-flat/watch-flat.ts"],"sourcesContent":["import {\n LitElement,\n PropertyValues,\n SVGTemplateResult,\n html,\n nothing,\n svg,\n unsafeCSS,\n} from 'lit';\nimport {property} from 'lit/decorators.js';\nimport compentStyle from './watch-flat.css?inline';\nimport {Tickmark, TickmarkStyle, tickmark} from './tickmark-flat.js';\nimport {rect} from '../../svghelpers/rectangular.js';\nimport {Label} from '../compass-flat/compass-flat.js';\nimport {customElement} from '../../decorator.js';\nimport {Priority} from '../types.js';\nimport {\n RotType,\n LinearRotPosition,\n renderLinearRotDots,\n renderLinearRotBarStatic,\n renderLinearRotBarDots,\n LINEAR_DOT_ANGLE_SPACING,\n renderLinearRotZeroPill,\n BAR_HALF_THICKNESS,\n ROT_ZERO_DEADBAND_PX,\n} from '../rate-of-turn/rot-renderer.js';\nimport {\n RateOfTurnController,\n disposeRotController,\n} from '../rate-of-turn/rate-of-turn.controller.js';\n\nexport {RotType, LinearRotPosition};\n\n/** Filled segment of the track band, in SVG user-space x-coordinates (center-origin). */\nexport interface WatchFlatBarArea {\n startX: number;\n endX: number;\n fillColor: string;\n}\n\n/** Needle marker spanning the track band at `x` (center-origin). */\nexport interface WatchFlatNeedle {\n x: number;\n fillColor: string;\n strokeColor: string;\n}\n\n/**\n * @property barAreas - Filled segments rendered inside the track band (the linear counterpart of the radial bar areas).\n * @property needles - Needle markers spanning the track band (the linear counterpart of the radial needles).\n * @availableWhen rotPosition rotType!=undefined\n * @property rotStartX - Bar start position in SVG user-space x-coordinates (center-origin). Computed by the parent instrument.\n * @availableWhen rotStartX rotType!=undefined\n * @property rotEndX - Bar end position in SVG user-space x-coordinates (center-origin). Computed by the parent instrument.\n * @availableWhen rotEndX rotType!=undefined\n * @property rotDotSpacing - Pixel spacing between adjacent dots in the linear ROT strip.\n * Must be > 0 to enable animation; the default `0` intentionally disables\n * the spinning dots so the parent instrument must supply a meaningful value\n * derived from the current scale (e.g. `LINEAR_DOT_ANGLE_SPACING * translationScale`).\n * @availableWhen rotDotSpacing rotType!=undefined\n * @availableWhen rotPriority rotType!=undefined\n * @availableWhen rotPortStarboard rotType!=undefined\n * @availableWhen rotAtZeroDeadband rotType==bar\n * @availableWhen rateOfTurnDegreesPerMinute rotType!=undefined\n * @availableWhen rotDotAnimationFactor rotType!=undefined\n * @experimental\n */\n@customElement('obc-watch-flat')\nexport class ObcWatchFlat extends LitElement {\n @property({type: Number}) width = 352;\n @property({type: Number}) height = 72;\n @property({type: Number}) padding = 0;\n @property({type: Number}) rotation = 0;\n @property({type: Number}) tickmarkSpacing = 0;\n @property({type: Number}) angleSetpoint: number | undefined;\n @property({type: Array, attribute: false}) tickmarks: Tickmark[] = [];\n @property({type: Array, attribute: false}) labels: Label[] = [];\n @property({type: Array, attribute: false}) FOVIndicator: SVGTemplateResult[] =\n [];\n @property({type: Number}) trackHeight = (2 / 3) * this.height;\n @property({type: Number}) ticksHeight = this.height - this.trackHeight;\n @property({type: Number}) borderRadius = 8;\n @property({type: Boolean}) bottomBar = false;\n @property({type: Array, attribute: false}) barAreas: WatchFlatBarArea[] = [];\n @property({type: Array, attribute: false}) needles: WatchFlatNeedle[] = [];\n\n @property({type: String}) rotType: RotType | undefined;\n @property({type: String}) rotPosition: LinearRotPosition =\n LinearRotPosition.track;\n @property({type: Number}) rotStartX: number = 0;\n @property({type: Number}) rotEndX: number = 0;\n @property({type: Number}) rotDotSpacing: number = 0;\n @property({type: String}) rotPriority: Priority = Priority.regular;\n @property({type: Boolean}) rotPortStarboard: boolean = false;\n @property({type: Number}) rotAtZeroDeadband: number = ROT_ZERO_DEADBAND_PX;\n\n @property({type: Number}) rateOfTurnDegreesPerMinute: number | undefined;\n @property({type: Number}) rotDotAnimationFactor: number = 18;\n\n /**\n * @deprecated Use `rateOfTurnDegreesPerMinute` (and optionally\n * `rotDotAnimationFactor`) instead. Takes effect only when\n * `rateOfTurnDegreesPerMinute` is `undefined`.\n */\n @property({type: Number})\n set rotationsPerMinute(value: number) {\n this._legacyRotationsPerMinute = value;\n }\n get rotationsPerMinute() {\n return this._legacyRotationsPerMinute;\n }\n\n private _legacyRotationsPerMinute = 0;\n private _rotController?: RateOfTurnController;\n\n private get _effectiveRpm(): number {\n if (this.rateOfTurnDegreesPerMinute != null) {\n return (\n (this.rateOfTurnDegreesPerMinute / 360) * this.rotDotAnimationFactor\n );\n }\n return this._legacyRotationsPerMinute;\n }\n\n private get totalHeight(): number {\n return this.bottomBar ? this.height + this.ticksHeight : this.height;\n }\n\n private renderClipPath(offsetY: number = 0): SVGTemplateResult {\n return svg`\n <clipPath id=\"frameClipPath${offsetY === 0 ? '' : 'Tickmarks'}\">\n <rect x=\"${-this.width / 2}\" y=\"${-this.totalHeight / 2 + offsetY}\" \n width=\"${this.width}\" height=\"${this.totalHeight}\" \n rx=\"${this.borderRadius}\" />\n </clipPath>\n `;\n }\n\n private renderLabelMask(): SVGTemplateResult {\n return svg`\n <mask id=\"labelMask\">\n <rect x=\"${-this.width / 2}\" y=\"${-70}\" \n width=\"${this.width}\" height=\"${32}\"\n />\n <linearGradient id=\"fadeGradient\" gradientUnits=\"userSpaceOnUse\"\n x1=\"${-this.width / 2}\" y1=\"0\" x2=\"${this.width / 2}\" y2=\"0\">\n <stop offset=\"0%\" style=\"stop-color:black; stop-opacity:1;\" />\n <stop offset=\"10%\" style=\"stop-color:white; stop-opacity:1;\" />\n <stop offset=\"50%\" style=\"stop-color:white; stop-opacity:1;\" />\n <stop offset=\"90%\" style=\"stop-color:white; stop-opacity:1;\" />\n <stop offset=\"100%\" style=\"stop-color:black; stop-opacity:1;\" />\n </linearGradient>\n <rect x=\"${-this.width / 2}\" y=\"${-70}\" \n width=\"${this.width}\" height=\"${32}\"\n fill=\"url(#fadeGradient)\" />\n </mask>\n `;\n }\n\n private renderLabels(scale: number): SVGTemplateResult[] {\n const labels: SVGTemplateResult[] = [];\n\n for (const l of this.labels) {\n labels.push(\n svg`<g transform=\"translate(${-this.rotation * this.tickmarkSpacing}, ${-6 / scale})\">\n <text x=${l.x} y=${l.y} class=\"label\" fill=${'var(--instrument-tick-mark-secondary-color)'}>\n ${l.text}\n </text>\n </g>`\n );\n }\n\n return labels;\n }\n\n private watchFace(): SVGTemplateResult {\n const strokeWidth = 1;\n const th = this.totalHeight;\n const topTicksY = -th / 2;\n\n return svg`\n ${this.renderClipPath()}\n ${this.renderClipPath(-40)}\n <g clip-path=\"url(#frameClipPath)\">\n ${rect('frame-track', {\n width: this.width,\n height: this.trackHeight,\n y:\n th / 2 - this.trackHeight - (this.bottomBar ? this.ticksHeight : 0),\n strokeWidth: strokeWidth,\n strokeColor: 'var(--instrument-frame-secondary-color)',\n strokePosition: 'inside',\n fillColor: 'var(--instrument-frame-secondary-color)',\n borderRadius: 0,\n })}\n ${rect('frame-ticks', {\n width: this.width,\n height: this.ticksHeight,\n y: topTicksY,\n strokeWidth: strokeWidth,\n strokeColor: 'var(--instrument-frame-primary-color)',\n strokePosition: 'inside',\n fillColor: 'var(--instrument-frame-primary-color)',\n borderRadius: 0,\n })}\n ${\n this.bottomBar\n ? rect('frame-bottom-bar', {\n width: this.width,\n height: this.ticksHeight,\n y: th / 2 - this.ticksHeight,\n strokeWidth: strokeWidth,\n strokeColor: 'var(--instrument-frame-primary-color)',\n strokePosition: 'inside',\n fillColor: 'var(--instrument-frame-primary-color)',\n borderRadius: 0,\n })\n : nothing\n }\n </g>\n ${rect('frame-outline', {\n width: this.width,\n height: th,\n strokeWidth: strokeWidth,\n strokeColor: 'var(--instrument-frame-tertiary-color)',\n strokePosition: 'inside',\n fillColor: 'none',\n borderRadius: this.borderRadius,\n })}\n `;\n }\n\n /** Top edge of the track band in SVG user space. */\n private get trackBandY(): number {\n return (\n this.totalHeight / 2 -\n this.trackHeight -\n (this.bottomBar ? this.ticksHeight : 0)\n );\n }\n\n private renderBandBars(): SVGTemplateResult[] | typeof nothing {\n if (this.barAreas.length === 0) {\n return nothing;\n }\n return this.barAreas.map(\n (bar) => svg`\n <rect\n x=\"${Math.min(bar.startX, bar.endX)}\"\n y=\"${this.trackBandY}\"\n width=\"${Math.abs(bar.endX - bar.startX)}\"\n height=\"${this.trackHeight}\"\n fill=${bar.fillColor}\n />\n `\n );\n }\n\n private renderBandNeedles(): SVGTemplateResult[] | typeof nothing {\n if (this.needles.length === 0) {\n return nothing;\n }\n return this.needles.map(\n (needle) => svg`\n <rect\n x=\"${needle.x - 4}\"\n y=\"${this.trackBandY}\"\n width=\"8\"\n height=\"${this.trackHeight}\"\n rx=\"4\"\n fill=${needle.fillColor}\n stroke=${needle.strokeColor}\n stroke-width=\"1\"\n vector-effect=\"non-scaling-stroke\"\n paint-order=\"stroke fill\"\n />\n `\n );\n }\n\n // ---------------------------------------------------------------------------\n // ROT (Rate of Turn) — linear\n // ---------------------------------------------------------------------------\n\n private getRotTrackY(): number {\n const th = this.totalHeight;\n if (this.rotPosition === LinearRotPosition.scale) {\n return -th / 2 + this.ticksHeight / 2;\n }\n if (this.bottomBar) {\n return th / 2 - this.ticksHeight / 2;\n }\n return this.height / 2 - this.trackHeight / 2;\n }\n\n private getRotColors(): {\n dotColor: string;\n barBgColor: string;\n } {\n const isEnhanced = this.rotPriority === Priority.enhanced;\n\n if (this.rotPortStarboard) {\n // For bar type, derive direction from bar positions (visual direction);\n // for dots, use spinner RPM.\n const direction =\n this.rotType === RotType.bar\n ? this.rotEndX - this.rotStartX\n : this._effectiveRpm;\n\n if (direction > 0) {\n return {\n dotColor: 'var(--instrument-starboard-secondary-color)',\n barBgColor: 'var(--instrument-starboard-primary-color)',\n };\n }\n if (direction < 0) {\n return {\n dotColor: 'var(--instrument-port-secondary-color)',\n barBgColor: 'var(--instrument-port-primary-color)',\n };\n }\n }\n\n return {\n dotColor: isEnhanced\n ? 'var(--instrument-enhanced-tertiary-color)'\n : 'var(--instrument-regular-tertiary-color)',\n barBgColor: isEnhanced\n ? 'var(--instrument-enhanced-secondary-color)'\n : 'var(--instrument-regular-secondary-color)',\n };\n }\n\n private renderRot(): SVGTemplateResult | typeof nothing {\n if (!this.rotType) return nothing;\n\n const trackY = this.getRotTrackY();\n const {dotColor, barBgColor} = this.getRotColors();\n const canAnimateDots = this.rotDotSpacing > 0;\n\n if (this.rotType === RotType.bar) {\n const span = Math.abs(this.rotEndX - this.rotStartX);\n const zeroDb = Number.isFinite(this.rotAtZeroDeadband)\n ? this.rotAtZeroDeadband\n : ROT_ZERO_DEADBAND_PX;\n\n if (span < Math.max(zeroDb, BAR_HALF_THICKNESS)) {\n return renderLinearRotZeroPill(barBgColor, this.rotStartX, trackY);\n }\n\n return svg`\n ${renderLinearRotBarStatic({\n startX: this.rotStartX,\n endX: this.rotEndX,\n barColor: barBgColor,\n trackY,\n maskId: 'rot-bar-mask-linear',\n })}\n ${\n canAnimateDots\n ? svg`<g clip-path=\"url(#rot-bar-mask-linear)\">\n <g id=\"rot-spinner\">\n ${renderLinearRotBarDots(dotColor, trackY, this.rotDotSpacing, this.width)}\n </g>\n </g>`\n : nothing\n }\n `;\n }\n\n const isEnhanced = this.rotPriority === Priority.enhanced;\n const neutralDotsColor = isEnhanced\n ? 'var(--instrument-enhanced-secondary-color)'\n : 'var(--instrument-regular-secondary-color)';\n let dotsColor = neutralDotsColor;\n if (this.rotPortStarboard) {\n if (this._effectiveRpm > 0) {\n dotsColor = 'var(--instrument-starboard-secondary-color)';\n } else if (this._effectiveRpm < 0) {\n dotsColor = 'var(--instrument-port-secondary-color)';\n }\n }\n return canAnimateDots\n ? svg`\n <g id=\"rot-spinner\">\n ${renderLinearRotDots(dotsColor, trackY, this.rotDotSpacing, this.width)}\n </g>\n `\n : nothing;\n }\n\n override updated(changed: PropertyValues): void {\n super.updated(changed);\n const el = this.rotType\n ? this.renderRoot.querySelector('#rot-spinner')\n : null;\n\n if (!el) {\n this._rotController = disposeRotController(this, this._rotController);\n return;\n }\n\n const cyclePx = 360 * (this.rotDotSpacing / LINEAR_DOT_ANGLE_SPACING);\n\n if (!this._rotController || this._rotController.el !== el) {\n this._rotController = disposeRotController(this, this._rotController);\n this._rotController = new RateOfTurnController(\n this,\n el,\n this._effectiveRpm,\n cyclePx\n );\n } else {\n this._rotController.cyclePx = cyclePx;\n }\n\n if (\n changed.has('rateOfTurnDegreesPerMinute') ||\n changed.has('rotDotAnimationFactor') ||\n changed.has('rotationsPerMinute')\n ) {\n this._rotController.rotationsPerMinute = this._effectiveRpm;\n }\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this._rotController = disposeRotController(this, this._rotController);\n }\n\n override render() {\n const width = (this.width / 2 + this.padding) * 2;\n const th = this.totalHeight;\n const viewBox = `-${width / 2} -${th / 2} ${width} ${th}`;\n const scale = this.clientWidth / width;\n\n const contentOffsetY = this.bottomBar ? -this.ticksHeight / 2 : 0;\n\n return html`\n <svg\n width=\"100%\"\n height=\"100%\"\n viewBox=${viewBox}\n style=\"--scale: ${scale}\"\n >\n ${this.watchFace()} ${this.renderLabelMask()}\n <g clip-path=\"url(#frameClipPath)\">\n ${this.renderBandBars()} ${this.renderBandNeedles()}\n </g>\n\n <g transform=\"translate(0, ${contentOffsetY})\">\n <g clip-path=\"url(#frameClipPath)\">\n ${this.tickmarks.map(\n (t) => svg`\n <g transform=\"translate(${-this.rotation * this.tickmarkSpacing}, 0)\">\n ${tickmark(t.angle, t.type, TickmarkStyle.regular)}\n </g>\n `\n )}\n </g>\n\n <g mask=\"url(#labelMask)\">${this.renderLabels(scale)}</g>\n </g>\n\n ${this.FOVIndicator}\n\n <g clip-path=\"url(#frameClipPath)\">${this.renderRot()}</g>\n ${svg`<line\n x1=\"0\" y1=\"${-this.totalHeight / 2 + this.ticksHeight}\"\n x2=\"0\" y2=\"${this.totalHeight / 2}\"\n stroke=\"var(--instrument-frame-tertiary-color)\"\n stroke-width=\"1\"\n vector-effect=\"non-scaling-stroke\"\n />`}\n </svg>\n `;\n }\n\n static override styles = unsafeCSS(compentStyle);\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'obc-watch-flat':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AA,GAAA,aAAA,WAAA,eAAA,KAAA,CAAA;AAEvB,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,aAAA,WAAA,aAAA,KAAA,CAAA;AACvB,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,aAAA,WAAA,WAAA,KAAA,CAAA;AACvB,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,aAAA,WAAA,iBAAA,KAAA,CAAA;AACvB,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,aAAA,WAAA,eAAA,KAAA,CAAA;AACvB,WAAA,CAAA,SAAS,EAAC,MAAM,QAAO,CAAC,CAAA,GAAA,aAAA,WAAA,oBAAA,KAAA,CAAA;AACxB,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,aAAA,WAAA,qBAAA,KAAA,CAAA;AAEvB,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,aAAA,WAAA,8BAAA,KAAA,CAAA;AACvB,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,aAAA,WAAA,yBAAA,KAAA,CAAA;AAOvB,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,aAAA,WAAA,sBAAA,IAAA;AArCzB,eAAA,WAAA,CAAA,cAAc,gBAAgB,CAAA,GAAA,YAAA"}
1
+ {"version":3,"file":"watch-flat.js","names":[],"sources":["../../../src/navigation-instruments/watch-flat/watch-flat.ts"],"sourcesContent":["import {\n LitElement,\n PropertyValues,\n SVGTemplateResult,\n html,\n nothing,\n svg,\n unsafeCSS,\n} from 'lit';\nimport {property} from 'lit/decorators.js';\nimport {ResizeController} from '@lit-labs/observers/resize-controller.js';\nimport compentStyle from './watch-flat.css?inline';\nimport {Tickmark, TickmarkStyle, tickmark} from './tickmark-flat.js';\nimport {rect} from '../../svghelpers/rectangular.js';\nimport {\n measureContainerPx,\n observeInnerBox,\n} from '../../svghelpers/radial-frame.js';\nimport {Label} from '../compass-flat/compass-flat.js';\nimport {customElement} from '../../decorator.js';\nimport {Priority} from '../types.js';\nimport {\n RotType,\n LinearRotPosition,\n renderLinearRotDots,\n renderLinearRotBarStatic,\n renderLinearRotBarDots,\n LINEAR_DOT_ANGLE_SPACING,\n renderLinearRotZeroPill,\n BAR_HALF_THICKNESS,\n ROT_ZERO_DEADBAND_PX,\n} from '../rate-of-turn/rot-renderer.js';\nimport {\n RateOfTurnController,\n disposeRotController,\n} from '../rate-of-turn/rate-of-turn.controller.js';\n\nexport {RotType, LinearRotPosition};\n\n/** Filled segment of the track band, in SVG user-space x-coordinates (center-origin). */\nexport interface WatchFlatBarArea {\n startX: number;\n endX: number;\n fillColor: string;\n}\n\n/** Needle marker spanning the track band at `x` (center-origin). */\nexport interface WatchFlatNeedle {\n x: number;\n fillColor: string;\n strokeColor: string;\n}\n\n/**\n * @property barAreas - Filled segments rendered inside the track band (the linear counterpart of the radial bar areas).\n * @property needles - Needle markers spanning the track band (the linear counterpart of the radial needles).\n * @availableWhen rotPosition rotType!=undefined\n * @property rotStartX - Bar start position in SVG user-space x-coordinates (center-origin). Computed by the parent instrument.\n * @availableWhen rotStartX rotType!=undefined\n * @property rotEndX - Bar end position in SVG user-space x-coordinates (center-origin). Computed by the parent instrument.\n * @availableWhen rotEndX rotType!=undefined\n * @property rotDotSpacing - Pixel spacing between adjacent dots in the linear ROT strip.\n * Must be > 0 to enable animation; the default `0` intentionally disables\n * the spinning dots so the parent instrument must supply a meaningful value\n * derived from the current scale (e.g. `LINEAR_DOT_ANGLE_SPACING * translationScale`).\n * @availableWhen rotDotSpacing rotType!=undefined\n * @availableWhen rotPriority rotType!=undefined\n * @availableWhen rotPortStarboard rotType!=undefined\n * @availableWhen rotAtZeroDeadband rotType==bar\n * @availableWhen rateOfTurnDegreesPerMinute rotType!=undefined\n * @availableWhen rotDotAnimationFactor rotType!=undefined\n * @experimental\n */\n@customElement('obc-watch-flat')\nexport class ObcWatchFlat extends LitElement {\n @property({type: Number}) width = 352;\n @property({type: Number}) height = 72;\n @property({type: Number}) padding = 0;\n @property({type: Number}) rotation = 0;\n @property({type: Number}) tickmarkSpacing = 0;\n @property({type: Number}) angleSetpoint: number | undefined;\n @property({type: Array, attribute: false}) tickmarks: Tickmark[] = [];\n @property({type: Array, attribute: false}) labels: Label[] = [];\n @property({type: Array, attribute: false}) FOVIndicator: SVGTemplateResult[] =\n [];\n @property({type: Number}) trackHeight = (2 / 3) * this.height;\n @property({type: Number}) ticksHeight = this.height - this.trackHeight;\n @property({type: Number}) borderRadius = 8;\n @property({type: Boolean}) bottomBar = false;\n @property({type: Array, attribute: false}) barAreas: WatchFlatBarArea[] = [];\n @property({type: Array, attribute: false}) needles: WatchFlatNeedle[] = [];\n\n @property({type: String}) rotType: RotType | undefined;\n @property({type: String}) rotPosition: LinearRotPosition =\n LinearRotPosition.track;\n @property({type: Number}) rotStartX: number = 0;\n @property({type: Number}) rotEndX: number = 0;\n @property({type: Number}) rotDotSpacing: number = 0;\n @property({type: String}) rotPriority: Priority = Priority.regular;\n @property({type: Boolean}) rotPortStarboard: boolean = false;\n @property({type: Number}) rotAtZeroDeadband: number = ROT_ZERO_DEADBAND_PX;\n\n @property({type: Number}) rateOfTurnDegreesPerMinute: number | undefined;\n @property({type: Number}) rotDotAnimationFactor: number = 18;\n\n /**\n * @deprecated Use `rateOfTurnDegreesPerMinute` (and optionally\n * `rotDotAnimationFactor`) instead. Takes effect only when\n * `rateOfTurnDegreesPerMinute` is `undefined`.\n */\n @property({type: Number})\n set rotationsPerMinute(value: number) {\n this._legacyRotationsPerMinute = value;\n }\n get rotationsPerMinute() {\n return this._legacyRotationsPerMinute;\n }\n\n private _legacyRotationsPerMinute = 0;\n private _rotController?: RateOfTurnController;\n private _resizeController = new ResizeController(this, {});\n\n private get _effectiveRpm(): number {\n if (this.rateOfTurnDegreesPerMinute != null) {\n return (\n (this.rateOfTurnDegreesPerMinute / 360) * this.rotDotAnimationFactor\n );\n }\n return this._legacyRotationsPerMinute;\n }\n\n /**\n * Rendered px per user-space unit; the labels divide by it to keep their\n * on-screen size. 1:1 while the strip has no width yet (hidden, or not laid\n * out), until the ResizeController re-renders it.\n */\n private scaleFor(viewBoxWidth: number): number {\n const scale = measureContainerPx(this).width / viewBoxWidth;\n return Number.isFinite(scale) && scale > 0 ? scale : 1;\n }\n\n private get totalHeight(): number {\n return this.bottomBar ? this.height + this.ticksHeight : this.height;\n }\n\n private renderClipPath(offsetY: number = 0): SVGTemplateResult {\n return svg`\n <clipPath id=\"frameClipPath${offsetY === 0 ? '' : 'Tickmarks'}\">\n <rect x=\"${-this.width / 2}\" y=\"${-this.totalHeight / 2 + offsetY}\" \n width=\"${this.width}\" height=\"${this.totalHeight}\" \n rx=\"${this.borderRadius}\" />\n </clipPath>\n `;\n }\n\n private renderLabelMask(): SVGTemplateResult {\n return svg`\n <mask id=\"labelMask\">\n <rect x=\"${-this.width / 2}\" y=\"${-70}\" \n width=\"${this.width}\" height=\"${32}\"\n />\n <linearGradient id=\"fadeGradient\" gradientUnits=\"userSpaceOnUse\"\n x1=\"${-this.width / 2}\" y1=\"0\" x2=\"${this.width / 2}\" y2=\"0\">\n <stop offset=\"0%\" style=\"stop-color:black; stop-opacity:1;\" />\n <stop offset=\"10%\" style=\"stop-color:white; stop-opacity:1;\" />\n <stop offset=\"50%\" style=\"stop-color:white; stop-opacity:1;\" />\n <stop offset=\"90%\" style=\"stop-color:white; stop-opacity:1;\" />\n <stop offset=\"100%\" style=\"stop-color:black; stop-opacity:1;\" />\n </linearGradient>\n <rect x=\"${-this.width / 2}\" y=\"${-70}\" \n width=\"${this.width}\" height=\"${32}\"\n fill=\"url(#fadeGradient)\" />\n </mask>\n `;\n }\n\n private renderLabels(scale: number): SVGTemplateResult[] {\n const labels: SVGTemplateResult[] = [];\n\n for (const l of this.labels) {\n labels.push(\n svg`<g transform=\"translate(${-this.rotation * this.tickmarkSpacing}, ${-6 / scale})\">\n <text x=${l.x} y=${l.y} class=\"label\" fill=${'var(--instrument-tick-mark-secondary-color)'}>\n ${l.text}\n </text>\n </g>`\n );\n }\n\n return labels;\n }\n\n private watchFace(): SVGTemplateResult {\n const strokeWidth = 1;\n const th = this.totalHeight;\n const topTicksY = -th / 2;\n\n return svg`\n ${this.renderClipPath()}\n ${this.renderClipPath(-40)}\n <g clip-path=\"url(#frameClipPath)\">\n ${rect('frame-track', {\n width: this.width,\n height: this.trackHeight,\n y:\n th / 2 - this.trackHeight - (this.bottomBar ? this.ticksHeight : 0),\n strokeWidth: strokeWidth,\n strokeColor: 'var(--instrument-frame-secondary-color)',\n strokePosition: 'inside',\n fillColor: 'var(--instrument-frame-secondary-color)',\n borderRadius: 0,\n })}\n ${rect('frame-ticks', {\n width: this.width,\n height: this.ticksHeight,\n y: topTicksY,\n strokeWidth: strokeWidth,\n strokeColor: 'var(--instrument-frame-primary-color)',\n strokePosition: 'inside',\n fillColor: 'var(--instrument-frame-primary-color)',\n borderRadius: 0,\n })}\n ${\n this.bottomBar\n ? rect('frame-bottom-bar', {\n width: this.width,\n height: this.ticksHeight,\n y: th / 2 - this.ticksHeight,\n strokeWidth: strokeWidth,\n strokeColor: 'var(--instrument-frame-primary-color)',\n strokePosition: 'inside',\n fillColor: 'var(--instrument-frame-primary-color)',\n borderRadius: 0,\n })\n : nothing\n }\n </g>\n ${rect('frame-outline', {\n width: this.width,\n height: th,\n strokeWidth: strokeWidth,\n strokeColor: 'var(--instrument-frame-tertiary-color)',\n strokePosition: 'inside',\n fillColor: 'none',\n borderRadius: this.borderRadius,\n })}\n `;\n }\n\n /** Top edge of the track band in SVG user space. */\n private get trackBandY(): number {\n return (\n this.totalHeight / 2 -\n this.trackHeight -\n (this.bottomBar ? this.ticksHeight : 0)\n );\n }\n\n private renderBandBars(): SVGTemplateResult[] | typeof nothing {\n if (this.barAreas.length === 0) {\n return nothing;\n }\n return this.barAreas.map(\n (bar) => svg`\n <rect\n x=\"${Math.min(bar.startX, bar.endX)}\"\n y=\"${this.trackBandY}\"\n width=\"${Math.abs(bar.endX - bar.startX)}\"\n height=\"${this.trackHeight}\"\n fill=${bar.fillColor}\n />\n `\n );\n }\n\n private renderBandNeedles(): SVGTemplateResult[] | typeof nothing {\n if (this.needles.length === 0) {\n return nothing;\n }\n return this.needles.map(\n (needle) => svg`\n <rect\n x=\"${needle.x - 4}\"\n y=\"${this.trackBandY}\"\n width=\"8\"\n height=\"${this.trackHeight}\"\n rx=\"4\"\n fill=${needle.fillColor}\n stroke=${needle.strokeColor}\n stroke-width=\"1\"\n vector-effect=\"non-scaling-stroke\"\n paint-order=\"stroke fill\"\n />\n `\n );\n }\n\n // ---------------------------------------------------------------------------\n // ROT (Rate of Turn) — linear\n // ---------------------------------------------------------------------------\n\n private getRotTrackY(): number {\n const th = this.totalHeight;\n if (this.rotPosition === LinearRotPosition.scale) {\n return -th / 2 + this.ticksHeight / 2;\n }\n if (this.bottomBar) {\n return th / 2 - this.ticksHeight / 2;\n }\n return this.height / 2 - this.trackHeight / 2;\n }\n\n private getRotColors(): {\n dotColor: string;\n barBgColor: string;\n } {\n const isEnhanced = this.rotPriority === Priority.enhanced;\n\n if (this.rotPortStarboard) {\n // For bar type, derive direction from bar positions (visual direction);\n // for dots, use spinner RPM.\n const direction =\n this.rotType === RotType.bar\n ? this.rotEndX - this.rotStartX\n : this._effectiveRpm;\n\n if (direction > 0) {\n return {\n dotColor: 'var(--instrument-starboard-secondary-color)',\n barBgColor: 'var(--instrument-starboard-primary-color)',\n };\n }\n if (direction < 0) {\n return {\n dotColor: 'var(--instrument-port-secondary-color)',\n barBgColor: 'var(--instrument-port-primary-color)',\n };\n }\n }\n\n return {\n dotColor: isEnhanced\n ? 'var(--instrument-enhanced-tertiary-color)'\n : 'var(--instrument-regular-tertiary-color)',\n barBgColor: isEnhanced\n ? 'var(--instrument-enhanced-secondary-color)'\n : 'var(--instrument-regular-secondary-color)',\n };\n }\n\n private renderRot(): SVGTemplateResult | typeof nothing {\n if (!this.rotType) return nothing;\n\n const trackY = this.getRotTrackY();\n const {dotColor, barBgColor} = this.getRotColors();\n const canAnimateDots = this.rotDotSpacing > 0;\n\n if (this.rotType === RotType.bar) {\n const span = Math.abs(this.rotEndX - this.rotStartX);\n const zeroDb = Number.isFinite(this.rotAtZeroDeadband)\n ? this.rotAtZeroDeadband\n : ROT_ZERO_DEADBAND_PX;\n\n if (span < Math.max(zeroDb, BAR_HALF_THICKNESS)) {\n return renderLinearRotZeroPill(barBgColor, this.rotStartX, trackY);\n }\n\n return svg`\n ${renderLinearRotBarStatic({\n startX: this.rotStartX,\n endX: this.rotEndX,\n barColor: barBgColor,\n trackY,\n maskId: 'rot-bar-mask-linear',\n })}\n ${\n canAnimateDots\n ? svg`<g clip-path=\"url(#rot-bar-mask-linear)\">\n <g id=\"rot-spinner\">\n ${renderLinearRotBarDots(dotColor, trackY, this.rotDotSpacing, this.width)}\n </g>\n </g>`\n : nothing\n }\n `;\n }\n\n const isEnhanced = this.rotPriority === Priority.enhanced;\n const neutralDotsColor = isEnhanced\n ? 'var(--instrument-enhanced-secondary-color)'\n : 'var(--instrument-regular-secondary-color)';\n let dotsColor = neutralDotsColor;\n if (this.rotPortStarboard) {\n if (this._effectiveRpm > 0) {\n dotsColor = 'var(--instrument-starboard-secondary-color)';\n } else if (this._effectiveRpm < 0) {\n dotsColor = 'var(--instrument-port-secondary-color)';\n }\n }\n return canAnimateDots\n ? svg`\n <g id=\"rot-spinner\">\n ${renderLinearRotDots(dotsColor, trackY, this.rotDotSpacing, this.width)}\n </g>\n `\n : nothing;\n }\n\n override firstUpdated(changed: PropertyValues): void {\n super.firstUpdated(changed);\n observeInnerBox(this._resizeController, this.renderRoot);\n }\n\n override updated(changed: PropertyValues): void {\n super.updated(changed);\n const el = this.rotType\n ? this.renderRoot.querySelector('#rot-spinner')\n : null;\n\n if (!el) {\n this._rotController = disposeRotController(this, this._rotController);\n return;\n }\n\n const cyclePx = 360 * (this.rotDotSpacing / LINEAR_DOT_ANGLE_SPACING);\n\n if (!this._rotController || this._rotController.el !== el) {\n this._rotController = disposeRotController(this, this._rotController);\n this._rotController = new RateOfTurnController(\n this,\n el,\n this._effectiveRpm,\n cyclePx\n );\n } else {\n this._rotController.cyclePx = cyclePx;\n }\n\n if (\n changed.has('rateOfTurnDegreesPerMinute') ||\n changed.has('rotDotAnimationFactor') ||\n changed.has('rotationsPerMinute')\n ) {\n this._rotController.rotationsPerMinute = this._effectiveRpm;\n }\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this._rotController = disposeRotController(this, this._rotController);\n }\n\n override render() {\n const width = (this.width / 2 + this.padding) * 2;\n const th = this.totalHeight;\n const viewBox = `-${width / 2} -${th / 2} ${width} ${th}`;\n const scale = this.scaleFor(width);\n\n const contentOffsetY = this.bottomBar ? -this.ticksHeight / 2 : 0;\n\n return html`\n <svg\n width=\"100%\"\n height=\"100%\"\n viewBox=${viewBox}\n style=\"--scale: ${scale}\"\n >\n ${this.watchFace()} ${this.renderLabelMask()}\n <g clip-path=\"url(#frameClipPath)\">\n ${this.renderBandBars()} ${this.renderBandNeedles()}\n </g>\n\n <g transform=\"translate(0, ${contentOffsetY})\">\n <g clip-path=\"url(#frameClipPath)\">\n ${this.tickmarks.map(\n (t) => svg`\n <g transform=\"translate(${-this.rotation * this.tickmarkSpacing}, 0)\">\n ${tickmark(t.angle, t.type, TickmarkStyle.regular)}\n </g>\n `\n )}\n </g>\n\n <g mask=\"url(#labelMask)\">${this.renderLabels(scale)}</g>\n </g>\n\n ${this.FOVIndicator}\n\n <g clip-path=\"url(#frameClipPath)\">${this.renderRot()}</g>\n ${svg`<line\n x1=\"0\" y1=\"${-this.totalHeight / 2 + this.ticksHeight}\"\n x2=\"0\" y2=\"${this.totalHeight / 2}\"\n stroke=\"var(--instrument-frame-tertiary-color)\"\n stroke-width=\"1\"\n vector-effect=\"non-scaling-stroke\"\n />`}\n </svg>\n `;\n }\n\n static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,eAAA,WAAA,CAAA,cAAc,gBAAgB,CAAA,GAAA,YAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oicl/openbridge-webcomponents-full-bundle",
3
- "version": "2.1.0-next.6",
3
+ "version": "2.1.0-next.7",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -129,6 +129,7 @@
129
129
  "test-storybook:watch": "vitest --project=storybook --watch",
130
130
  "test-a11y": "vitest run --config vitest.a11y.config.ts && tsx ./script/check-a11y-baseline.ts",
131
131
  "test-a11y:update": "vitest run --config vitest.a11y.config.ts && tsx ./script/check-a11y-baseline.ts --update",
132
+ "test-hidden-mount": "vitest run --config vitest.hidden-mount.config.ts",
132
133
  "build-storybook": "storybook build",
133
134
  "storybook:server": "http-server -p 6006 storybook-static",
134
135
  "preview": "vite preview",
@@ -234,7 +234,9 @@ export class ObcChartObjectVesselButton extends LitElement {
234
234
  if (!hasTurnRate) {
235
235
  return nothing;
236
236
  }
237
- const deg = (this.turnRate / 100) * 12;
237
+ // A binding that passes `undefined` would put NaN in the arc path.
238
+ const turnRate = Number.isFinite(this.turnRate) ? this.turnRate : 0;
239
+ const deg = (turnRate / 100) * 12;
238
240
  const R = 24;
239
241
  const x = -R * Math.cos(degToRad(deg)) + R + 3;
240
242
  const y = R * Math.sin(degToRad(deg)) + 8;
@@ -7,6 +7,14 @@ canvas {
7
7
  position: relative;
8
8
  }
9
9
 
10
+ /* Pixel mode: pin the canvas to the requested size. Chart.js writes its
11
+ measured size back inline, so a chart created in a hidden container would
12
+ otherwise keep the 48 px minimum it measured there. */
13
+ :host(:not([fixedaspectratioscaling])) canvas {
14
+ width: var(--chart-width, 100%) !important;
15
+ height: var(--chart-height, auto) !important;
16
+ }
17
+
10
18
  /* Scale slots - absolutely positioned at edges */
11
19
  slot[name="top-scale"],
12
20
  slot[name="bottom-scale"],
@@ -2285,25 +2285,30 @@ export class ObcChartLineBase extends LitElement {
2285
2285
  * NOTE: For non-threshold modes (solid, semitransparent), backgroundColor is already
2286
2286
  * set correctly in buildDataset(). This method now only handles threshold gradients
2287
2287
  * which require Chart.js scales to be available.
2288
+ *
2289
+ * @returns Whether it set gradients; they reach the drawn chart on its next update.
2288
2290
  */
2289
- protected applyFillModes() {
2291
+ protected applyFillModes(): boolean {
2290
2292
  // Guard: Verify chart and canvas exist and are connected
2291
- if (!this.chart || !this.canvasEl || !this.canvasEl.isConnected) return;
2293
+ if (!this.chart || !this.canvasEl || !this.canvasEl.isConnected)
2294
+ return false;
2292
2295
 
2293
2296
  const chart = this.chart; // Store reference for TypeScript
2294
2297
  const ctx = chart.ctx as CanvasRenderingContext2D;
2295
2298
 
2296
2299
  // Guard: Verify canvas context is available
2297
- if (!ctx) return;
2300
+ if (!ctx) return false;
2298
2301
 
2299
2302
  const fill = this.shouldApplyFill();
2300
2303
  const fillMode = this.getFillMode();
2301
2304
 
2302
2305
  // Only process threshold mode - other modes already have correct backgroundColor from buildDataset()
2303
2306
  if (fillMode !== 'threshold' || !fill) {
2304
- return;
2307
+ return false;
2305
2308
  }
2306
2309
 
2310
+ let applied = false;
2311
+
2307
2312
  chart.data.datasets.forEach((ds, _idx) => {
2308
2313
  const dataset = ds as ChartDataset<'line'> & {
2309
2314
  fill?:
@@ -2369,7 +2374,9 @@ export class ObcChartLineBase extends LitElement {
2369
2374
  const borderGradient = createGradient(0.8, 0.8);
2370
2375
  dataset.backgroundColor = fillGradient as unknown as string;
2371
2376
  dataset.borderColor = borderGradient as unknown as string;
2377
+ applied = true;
2372
2378
  });
2379
+ return applied;
2373
2380
  }
2374
2381
 
2375
2382
  // Update external library AFTER render
@@ -3219,7 +3226,11 @@ export class ObcChartLineBase extends LitElement {
3219
3226
 
3220
3227
  // Defer legend update to next tick to ensure Chart.js metadata is initialized
3221
3228
  requestAnimationFrame(() => this.updateLegend());
3222
- this.applyFillModes();
3229
+ // The constructor has already resolved the dataset colours, so a chart
3230
+ // rebuilt with nothing updating it after would keep its pre-gradient line.
3231
+ if (this.applyFillModes()) {
3232
+ this.chart.update('none');
3233
+ }
3223
3234
  this.syncSlottedScaleRanges();
3224
3235
  }
3225
3236
 
@@ -43,4 +43,32 @@ describe('observeLabelThreshold', () => {
43
43
 
44
44
  expect(events).toEqual(['update', 'rebuild', 'update', 'rebuild']);
45
45
  });
46
+
47
+ it('rebuilds once when a target created without a size gets one', async () => {
48
+ const parent = document.createElement('div');
49
+ parent.style.display = 'none';
50
+ el = document.createElement('div');
51
+ el.style.height = '100px';
52
+ parent.append(el);
53
+ document.body.append(parent);
54
+ const events: string[] = [];
55
+
56
+ observer = observeLabelThreshold(
57
+ el,
58
+ () => (el?.clientHeight ?? 0) >= THRESHOLD_PX,
59
+ {
60
+ rebuild: () => events.push('rebuild'),
61
+ update: () => events.push('update'),
62
+ }
63
+ );
64
+ await settle();
65
+
66
+ parent.style.display = 'block';
67
+ await settle();
68
+ el.style.height = '120px';
69
+ await settle();
70
+ parent.remove();
71
+
72
+ expect(events).toEqual(['update', 'rebuild', 'update']);
73
+ });
46
74
  });
@@ -1,6 +1,11 @@
1
+ function hasSize(target: Element): boolean {
2
+ const {width, height} = target.getBoundingClientRect();
3
+ return width > 0 && height > 0;
4
+ }
5
+
1
6
  /** What a chart does when its canvas is resized. */
2
7
  export interface LabelThresholdCallbacks {
3
- /** The resize crossed the threshold. */
8
+ /** The resize crossed the threshold, or gave the canvas its first size. */
4
9
  rebuild(): void;
5
10
  /** The resize stayed on one side of it. */
6
11
  update(): void;
@@ -12,9 +17,14 @@ export interface LabelThresholdCallbacks {
12
17
  * therefore needs a rebuild, while every other resize is an in-place
13
18
  * update. This owns the which-side state; the chart owns the decision.
14
19
  *
20
+ * A chart created while its canvas had no size (in a hidden container) is
21
+ * also rebuilt once, when the canvas first gets one: Chart.js keeps layout
22
+ * state from that empty first pass, and a resize leaves the plot a pixel off
23
+ * a chart created at its real size.
24
+ *
15
25
  * @param target - The chart's canvas. A detached target is ignored: it has no size and no chart to serve.
16
26
  * @param isAboveThreshold - The chart's own test, read once now and after every resize.
17
- * @param callbacks - `rebuild` on a crossing, `update` otherwise.
27
+ * @param callbacks - `rebuild` on a crossing or a first size, `update` otherwise.
18
28
  * @returns The observer, for the chart to disconnect in `disconnectedCallback`.
19
29
  */
20
30
  export function observeLabelThreshold(
@@ -23,12 +33,15 @@ export function observeLabelThreshold(
23
33
  callbacks: LabelThresholdCallbacks
24
34
  ): ResizeObserver {
25
35
  let wasAbove = isAboveThreshold();
36
+ let hadSize = hasSize(target);
26
37
  const observer = new ResizeObserver(() => {
27
38
  if (!target.isConnected) return;
28
39
  const isAbove = isAboveThreshold();
29
40
  const crossed = isAbove !== wasAbove;
30
41
  wasAbove = isAbove;
31
- if (crossed) {
42
+ const gotSize = !hadSize && hasSize(target);
43
+ hadSize = hasSize(target);
44
+ if (crossed || gotSize) {
32
45
  callbacks.rebuild();
33
46
  } else {
34
47
  callbacks.update();
@@ -0,0 +1,36 @@
1
+ import {describe, expect, it} from 'vitest';
2
+ import {render} from 'vitest-browser-lit';
3
+ import {html} from 'lit';
4
+ import './rot-linear.js';
5
+ import type {ObcRotLinear} from './rot-linear.js';
6
+ import type {ObcWatchFlat} from '../watch-flat/watch-flat.js';
7
+ import '../../main.css';
8
+
9
+ describe('obc-rot-linear — scale labels', () => {
10
+ it('sizes its labels once a container hidden at mount is shown', async () => {
11
+ const screen = render(
12
+ html`<div style="display: none; width: 512px; height: 170px">
13
+ <obc-rot-linear .rateOfTurnDegreesPerMinute=${45}></obc-rot-linear>
14
+ </div>`
15
+ );
16
+ const el = screen.container.querySelector('obc-rot-linear') as ObcRotLinear;
17
+ await el.updateComplete;
18
+ const strip = el.shadowRoot!.querySelector(
19
+ 'obc-watch-flat'
20
+ ) as ObcWatchFlat;
21
+ await strip.updateComplete;
22
+
23
+ (el.parentElement as HTMLElement).style.display = 'block';
24
+ for (let i = 0; i < 2; i++) {
25
+ await new Promise((resolve) => requestAnimationFrame(resolve));
26
+ }
27
+ await strip.updateComplete;
28
+
29
+ const label = strip.shadowRoot!.querySelector('text.label')!;
30
+ expect(label.parentElement!.getAttribute('transform')).not.toContain(
31
+ 'Infinity'
32
+ );
33
+ // 16px on screen: the strip is 512px wide for 352 user units.
34
+ expect(getComputedStyle(label).fontSize).toBe('11px');
35
+ });
36
+ });
@@ -0,0 +1,76 @@
1
+ import {describe, expect, it} from 'vitest';
2
+ import {render} from 'vitest-browser-lit';
3
+ import {html} from 'lit';
4
+ import './watch-flat.js';
5
+ import type {ObcWatchFlat} from './watch-flat.js';
6
+ import {LabelPosition} from '../compass-flat/compass-flat.js';
7
+ import '../../main.css';
8
+
9
+ const LABELS = [
10
+ {x: -88, y: LabelPosition.top, text: '-45'},
11
+ {x: 0, y: LabelPosition.top, text: '0'},
12
+ {x: 88, y: LabelPosition.top, text: '45'},
13
+ ];
14
+
15
+ /** Two frames: one for the ResizeObserver callback, one for the re-render. */
16
+ async function settle(el: ObcWatchFlat): Promise<void> {
17
+ for (let i = 0; i < 2; i++) {
18
+ await new Promise((resolve) => requestAnimationFrame(resolve));
19
+ }
20
+ await el.updateComplete;
21
+ }
22
+
23
+ function labelGeometry(el: ObcWatchFlat): {offsetY: number; scale: number} {
24
+ const group = el.shadowRoot!.querySelector('text.label')!.parentElement!;
25
+ const transform = group.getAttribute('transform') ?? '';
26
+ const svg = el.shadowRoot!.querySelector('svg')!;
27
+ return {
28
+ offsetY: Number(/translate\([^,]+,\s*([^)]+)\)/.exec(transform)?.[1]),
29
+ scale: Number(svg.style.getPropertyValue('--scale')),
30
+ };
31
+ }
32
+
33
+ function mount(display: string, width: number) {
34
+ const screen = render(
35
+ html`<div style="display: ${display}; width: ${width}px; height: 72px">
36
+ <obc-watch-flat
37
+ style="display: block; width: 100%; height: 100%"
38
+ .labels=${LABELS}
39
+ ></obc-watch-flat>
40
+ </div>`
41
+ );
42
+ const el = screen.container.querySelector('obc-watch-flat') as ObcWatchFlat;
43
+ return {box: el.parentElement as HTMLElement, el};
44
+ }
45
+
46
+ describe('obc-watch-flat — label scale follows the rendered width', () => {
47
+ it('renders finite labels when it first paints at zero width', async () => {
48
+ const {el} = mount('none', 352);
49
+ await el.updateComplete;
50
+
51
+ const {offsetY, scale} = labelGeometry(el);
52
+ expect(Number.isFinite(offsetY)).toBe(true);
53
+ expect(scale).toBeGreaterThan(0);
54
+ });
55
+
56
+ it('picks up its width once a hidden container is shown', async () => {
57
+ const {box, el} = mount('none', 704);
58
+ await el.updateComplete;
59
+
60
+ box.style.display = 'block';
61
+ await settle(el);
62
+
63
+ expect(labelGeometry(el)).toEqual({offsetY: -3, scale: 2});
64
+ });
65
+
66
+ it('re-scales the labels when the container is resized', async () => {
67
+ const {box, el} = mount('block', 352);
68
+ await settle(el);
69
+ expect(labelGeometry(el).scale).toBe(1);
70
+
71
+ box.style.width = '704px';
72
+ await settle(el);
73
+
74
+ expect(labelGeometry(el)).toEqual({offsetY: -3, scale: 2});
75
+ });
76
+ });