@oicl/openbridge-webcomponents-full-bundle 2.2.0-next.24 → 2.2.0-next.25

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 (28) hide show
  1. package/bundle/openbridge-webcomponents.bundle.js +528 -198
  2. package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
  3. package/custom-elements.json +271 -0
  4. package/dist/navigation-instruments/attitude/attitude.css_inline.js +64 -0
  5. package/dist/navigation-instruments/attitude/attitude.css_inline.js.map +1 -0
  6. package/dist/navigation-instruments/attitude/attitude.d.ts +121 -0
  7. package/dist/navigation-instruments/attitude/attitude.d.ts.map +1 -0
  8. package/dist/navigation-instruments/attitude/attitude.js +255 -0
  9. package/dist/navigation-instruments/attitude/attitude.js.map +1 -0
  10. package/dist/navigation-instruments/watch/tickmark.d.ts.map +1 -1
  11. package/dist/navigation-instruments/watch/tickmark.js +35 -13
  12. package/dist/navigation-instruments/watch/tickmark.js.map +1 -1
  13. package/dist/svghelpers/math.d.ts +7 -0
  14. package/dist/svghelpers/math.d.ts.map +1 -1
  15. package/dist/svghelpers/math.js +10 -1
  16. package/dist/svghelpers/math.js.map +1 -1
  17. package/llms/components/obc-attitude.md +69 -0
  18. package/llms/llms-full.txt +72 -0
  19. package/llms/llms.txt +1 -0
  20. package/package.json +1 -1
  21. package/src/navigation-instruments/attitude/attitude.css +54 -0
  22. package/src/navigation-instruments/attitude/attitude.spec.ts +208 -0
  23. package/src/navigation-instruments/attitude/attitude.stories.ts +87 -0
  24. package/src/navigation-instruments/attitude/attitude.ts +351 -0
  25. package/src/navigation-instruments/watch/tickmark.spec.ts +22 -0
  26. package/src/navigation-instruments/watch/tickmark.ts +49 -5
  27. package/src/svghelpers/math.spec.ts +25 -0
  28. package/src/svghelpers/math.ts +10 -0
@@ -14687,6 +14687,78 @@ This component does not use slots. The image is provided via the `imageSrc` prop
14687
14687
 
14688
14688
  ---
14689
14689
 
14690
+ # `<obc-attitude>`
14691
+
14692
+ Attitude instrument that shows pitch and roll as a moving horizon behind a fixed vessel symbol, the way an artificial horizon does.
14693
+
14694
+ Lifecycle: experimental. [Storybook](https://openbridge-next-storybook.web.app/?path=/docs/instruments-attitude--docs) · [Source](https://raw.githubusercontent.com/Ocean-Industries-Concept-Lab/openbridge-webcomponents/develop/packages/openbridge-webcomponents/src/navigation-instruments/attitude/attitude.ts)
14695
+
14696
+ `<obc-attitude>` – Attitude instrument that shows pitch and roll as a moving
14697
+ horizon behind a fixed vessel symbol, the way an artificial horizon does.
14698
+
14699
+ The symbol in the centre stays level. The ground half of the face slides
14700
+ down as the pitch rises and tilts against the roll, so the picture matches
14701
+ what is seen looking forward. A ladder of short rungs on the horizon gives
14702
+ the pitch. The roll scale turns with the horizon, and the pointer at the
14703
+ top, which stays straight up like the symbol, reads the roll on it.
14704
+
14705
+ ## Features / Variants
14706
+
14707
+ - **Roll scale:** the band over the sky half of the face, labelled
14708
+ 90/45/0/45/90. It turns with the horizon, so the fixed pointer sits on
14709
+ the side the vehicle rolls to. `showLabels` turns the labels off.
14710
+ - **Full turns:** `pitch` and `roll` take any angle. Past ±90° of pitch the
14711
+ ladder runs on to the inverted horizon, with the ground above the sky,
14712
+ and the roll scale follows the sky to the lower half.
14713
+ - **Pitch ladder:** one rung per `pitchTickInterval` degrees. A smaller
14714
+ interval magnifies the pitch; a larger one shows more of it.
14715
+ - **Priority:** `priority` switches the symbol and the pointer between the
14716
+ `regular` and `enhanced` palette.
14717
+
14718
+ ## Usage Guidelines
14719
+
14720
+ Use for a vehicle that is steered in three dimensions and whose operator
14721
+ needs pitch and roll together at a glance. For readings against a scale
14722
+ with advice zones use `obc-pitch`, `obc-roll` or `obc-pitch-roll`; for
14723
+ pitch, roll and yaw deviation as a dot on a polar grid use
14724
+ `obc-pitch-roll-yaw`.
14725
+
14726
+ The scales carry no numbers besides the roll labels. Put the values next to
14727
+ the instrument with `obc-readout` when they have to be read exactly.
14728
+
14729
+ **TODO(designer)**: Figma 20108:142407 shows no pitch values on the ladder.
14730
+
14731
+ ## Properties
14732
+
14733
+ | Property | Attribute | Type | Default | Description |
14734
+ | --- | --- | --- | --- | --- |
14735
+ | pitch | pitch | `number` | `0` | Pitch in degrees, positive with the front up. The horizon drops below the symbol as it rises. Any angle is accepted and wraps over a full turn. |
14736
+ | roll | roll | `number` | `0` | Roll in degrees, positive with the right side down. The horizon and the roll scale turn the other way, as they appear from on board. Any angle is accepted. |
14737
+ | pitchTickInterval | pitchTickInterval | `number` | `10` | Degrees of pitch between two ladder rungs, from 0.1 to 90. Default `10`, which shows about ±29° on the face. |
14738
+ | showLabels | | `boolean` | `true` | When `true` (default), labels the roll scale. |
14739
+ | priority | priority | `Priority` | | Palette of the symbol and the pointer: `regular` or `enhanced`. |
14740
+ | faceDiameter | face-diameter | `number \| undefined` | | Outer-ring diameter in CSS pixels. When set, the instrument renders at a fixed size, so instruments that share the value have rings of the same size. |
14741
+
14742
+ ## Events
14743
+
14744
+ None.
14745
+
14746
+ ## Slots
14747
+
14748
+ None.
14749
+
14750
+ ## Stories
14751
+
14752
+ - [Default](https://openbridge-next-storybook.web.app/?path=/story/instruments-attitude--default): Level, as the design draws it (Figma 20108:142406).
14753
+ - [Enhanced](https://openbridge-next-storybook.web.app/?path=/story/instruments-attitude--enhanced)
14754
+ - [Pitch And Roll](https://openbridge-next-storybook.web.app/?path=/story/instruments-attitude--pitch-and-roll): Front up and right side down: the horizon drops and tilts to the left, and the roll scale turns with it under the pointer.
14755
+ - [Inverted](https://openbridge-next-storybook.web.app/?path=/story/instruments-attitude--inverted): Past half a turn of pitch the ladder shows the inverted horizon, ground on top. The roll scale follows the sky to the lower half, away from the pointer.
14756
+ - [Fine Ladder](https://openbridge-next-storybook.web.app/?path=/story/instruments-attitude--fine-ladder): One rung is 5°, so the same pitch moves the horizon twice as far.
14757
+ - [Without Labels](https://openbridge-next-storybook.web.app/?path=/story/instruments-attitude--without-labels)
14758
+ - [Small](https://openbridge-next-storybook.web.app/?path=/story/instruments-attitude--small): The roll labels keep their text size, so a small face gives up room to them.
14759
+
14760
+ ---
14761
+
14690
14762
  # `<obc-azimuth-thruster>`
14691
14763
 
14692
14764
  No summary yet.
package/llms/llms.txt CHANGED
@@ -168,6 +168,7 @@ React, Vue, Angular and Svelte wrappers.
168
168
 
169
169
  ## Navigation instruments and indicators
170
170
 
171
+ - [obc-attitude](https://openbridge-next-storybook.web.app/components/obc-attitude.md): Attitude instrument that shows pitch and roll as a moving horizon behind a fixed vessel symbol, the way an artificial horizon does. (experimental)
171
172
  - [obc-azimuth-thruster](https://openbridge-next-storybook.web.app/components/obc-azimuth-thruster.md): no summary yet (stable)
172
173
  - [obc-azimuth-thruster-labeled](https://openbridge-next-storybook.web.app/components/obc-azimuth-thruster-labeled.md): no summary yet (deprecated: The azimuth-thruster-labeled component is deprecated and will be removed in future releases.)
173
174
  - [obc-badge-command](https://openbridge-next-storybook.web.app/components/obc-badge-command.md): no summary yet (stable)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oicl/openbridge-webcomponents-full-bundle",
3
- "version": "2.2.0-next.24",
3
+ "version": "2.2.0-next.25",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,54 @@
1
+ * {
2
+ box-sizing: border-box;
3
+ }
4
+
5
+ .container {
6
+ position: relative; /* containing block for the three stacked layers */
7
+ width: 100%;
8
+ height: 100%;
9
+
10
+ --attitude-symbol-color: var(--element-neutral-color);
11
+ --attitude-accent-color: var(--instrument-regular-secondary-color);
12
+ }
13
+
14
+ .container.enhanced {
15
+ --attitude-symbol-color: var(--element-neutral-enhanced-color);
16
+ --attitude-accent-color: var(--instrument-enhanced-secondary-color);
17
+ }
18
+
19
+ /* The horizon sits under the watch so the roll scale band covers it. */
20
+ .container > obc-watch,
21
+ .container > svg {
22
+ position: absolute;
23
+ top: 0;
24
+ left: 0;
25
+ width: 100%;
26
+ height: 100%;
27
+ }
28
+
29
+ .ground {
30
+ fill: var(--instrument-frame-secondary-color);
31
+ }
32
+
33
+ /* Regular colour in both priorities, as the design draws it. */
34
+ .horizon-line {
35
+ stroke: var(--instrument-regular-secondary-color);
36
+ stroke-width: 2;
37
+ }
38
+
39
+ .rung {
40
+ stroke: var(--instrument-frame-tertiary-color);
41
+ }
42
+
43
+ .face-outline {
44
+ fill: none;
45
+ stroke: var(--instrument-frame-tertiary-color);
46
+ }
47
+
48
+ .vessel-symbol path {
49
+ fill: var(--attitude-symbol-color);
50
+ }
51
+
52
+ .vessel-symbol circle {
53
+ fill: var(--attitude-accent-color);
54
+ }
@@ -0,0 +1,208 @@
1
+ import {describe, expect, it} from 'vitest';
2
+ import {render} from 'vitest-browser-lit';
3
+ import {html} from 'lit';
4
+ import './attitude.js';
5
+ import type {ObcAttitude} from './attitude.js';
6
+ import type {ObcWatch} from '../watch/watch.js';
7
+ import '../../main.css';
8
+
9
+ /** One ladder rung, in SVG units; a rung is `pitchTickInterval` degrees. */
10
+ const RUNG = 64;
11
+
12
+ async function mount(props: Partial<ObcAttitude> = {}): Promise<ObcAttitude> {
13
+ const screen = render(
14
+ html`<div style="width: 512px; height: 512px">
15
+ <obc-attitude></obc-attitude>
16
+ </div>`
17
+ );
18
+ const el = screen.container.querySelector('obc-attitude') as ObcAttitude;
19
+ Object.assign(el, props);
20
+ await el.updateComplete;
21
+ return el;
22
+ }
23
+
24
+ /** The numbers of one `name(a b)` function in a transform attribute. */
25
+ function transformOf(el: Element | null, name: string): number[] {
26
+ const match = new RegExp(`${name}\\(([^)]*)\\)`).exec(
27
+ el?.getAttribute('transform') ?? ''
28
+ );
29
+ return match
30
+ ? match[1]
31
+ .trim()
32
+ .split(/[\s,]+/)
33
+ .map(Number)
34
+ : [];
35
+ }
36
+
37
+ function horizonOf(el: ObcAttitude): SVGGElement {
38
+ return el.shadowRoot!.querySelector<SVGGElement>('g.horizon')!;
39
+ }
40
+
41
+ function numbers(el: ObcAttitude, selector: string, attr: string): number[] {
42
+ return [...el.shadowRoot!.querySelectorAll(selector)]
43
+ .map((node) => Number(node.getAttribute(attr)))
44
+ .sort((a, b) => a - b);
45
+ }
46
+
47
+ /** Whether a ground band covers the point `dy` units below the face centre. */
48
+ function groundAt(el: ObcAttitude, dy: number): boolean {
49
+ const [, shift] = transformOf(horizonOf(el), 'translate');
50
+ const y = dy - shift;
51
+ return [...el.shadowRoot!.querySelectorAll('rect.ground')].some((rect) => {
52
+ const top = Number(rect.getAttribute('y'));
53
+ return y >= top && y <= top + Number(rect.getAttribute('height'));
54
+ });
55
+ }
56
+
57
+ function watchOf(el: ObcAttitude): ObcWatch {
58
+ return el.shadowRoot!.querySelector('obc-watch') as ObcWatch;
59
+ }
60
+
61
+ describe('obc-attitude — the horizon follows pitch and roll', () => {
62
+ it('sits level through the centre at zero pitch and roll', async () => {
63
+ const horizon = horizonOf(await mount());
64
+ expect(transformOf(horizon, 'rotate')).toEqual([0]);
65
+ expect(transformOf(horizon, 'translate')).toEqual([0, 0]);
66
+ });
67
+
68
+ it('drops one rung per pitchTickInterval of positive pitch', async () => {
69
+ const el = await mount({pitch: 10});
70
+ expect(transformOf(horizonOf(el), 'translate')).toEqual([0, RUNG]);
71
+ el.pitchTickInterval = 5;
72
+ await el.updateComplete;
73
+ expect(transformOf(horizonOf(el), 'translate')).toEqual([0, 2 * RUNG]);
74
+ });
75
+
76
+ it('tilts against the roll', async () => {
77
+ const el = await mount({roll: 30});
78
+ expect(transformOf(horizonOf(el), 'rotate')).toEqual([-30]);
79
+ });
80
+
81
+ it('keeps the ground below the centre when level', async () => {
82
+ const el = await mount();
83
+ expect(groundAt(el, 10)).toBe(true);
84
+ expect(groundAt(el, -10)).toBe(false);
85
+ });
86
+ });
87
+
88
+ describe('obc-attitude — pitch wraps over a full turn', () => {
89
+ it('draws a full turn the same as no turn', async () => {
90
+ const el = await mount({pitch: 370});
91
+ expect(transformOf(horizonOf(el), 'translate')).toEqual([0, RUNG]);
92
+ });
93
+
94
+ it('shows the ground above the centre when pitched half a turn', async () => {
95
+ const el = await mount({pitch: 180});
96
+ expect(groundAt(el, -10)).toBe(true);
97
+ expect(groundAt(el, 10)).toBe(false);
98
+ });
99
+
100
+ it('shows only sky when pointing straight up', async () => {
101
+ const el = await mount({pitch: 90});
102
+ expect(groundAt(el, -180)).toBe(false);
103
+ expect(groundAt(el, 0)).toBe(false);
104
+ expect(groundAt(el, 180)).toBe(false);
105
+ });
106
+ });
107
+
108
+ describe('obc-attitude — pitch ladder', () => {
109
+ /** Rung positions measured from the face centre, along the ladder. */
110
+ const rungOffsets = (el: ObcAttitude) => {
111
+ const [, shift] = transformOf(horizonOf(el), 'translate');
112
+ return numbers(el, 'line.rung', 'y1').map((y) => y + shift);
113
+ };
114
+
115
+ it('treats an interval below a tenth of a degree as a tenth', async () => {
116
+ const el = await mount({pitch: 100, pitchTickInterval: 1e-10});
117
+ expect(transformOf(horizonOf(el), 'translate')).toEqual([0, 1000 * RUNG]);
118
+ expect(numbers(el, 'line.rung', 'y1').length).toBeLessThanOrEqual(7);
119
+ });
120
+
121
+ it('mirrors the rungs around the inverted horizon for any interval', async () => {
122
+ const offsets = rungOffsets(
123
+ await mount({pitch: 180, pitchTickInterval: 7})
124
+ );
125
+ expect(offsets.length).toBeGreaterThan(0);
126
+ offsets.forEach((offset, i) =>
127
+ expect(offset).toBeCloseTo(-offsets[offsets.length - 1 - i], 6)
128
+ );
129
+ });
130
+
131
+ it('does not shift the rungs as the pitch passes half a turn', async () => {
132
+ const before = rungOffsets(
133
+ await mount({pitch: 179.99, pitchTickInterval: 7})
134
+ );
135
+ const after = rungOffsets(
136
+ await mount({pitch: 180.01, pitchTickInterval: 7})
137
+ );
138
+ expect(after).toHaveLength(before.length);
139
+ after.forEach((offset, i) =>
140
+ expect(Math.abs(offset - before[i])).toBeLessThan(1)
141
+ );
142
+ });
143
+
144
+ it('draws a rung every 64 units and none on the horizon line', async () => {
145
+ const el = await mount();
146
+ const rungs = numbers(el, 'line.rung', 'y1');
147
+ expect(rungs).toEqual([-2 * RUNG, -RUNG, RUNG, 2 * RUNG]);
148
+ });
149
+
150
+ it('keeps the rungs around the centre as the ladder slides', async () => {
151
+ const el = await mount({pitch: 40});
152
+ const rungs = numbers(el, 'line.rung', 'y1');
153
+ expect(rungs).toEqual([
154
+ -6 * RUNG,
155
+ -5 * RUNG,
156
+ -4 * RUNG,
157
+ -3 * RUNG,
158
+ -2 * RUNG,
159
+ ]);
160
+ });
161
+ });
162
+
163
+ describe('obc-attitude — roll scale and pointer', () => {
164
+ it('keeps the pointer straight up while the vehicle rolls', async () => {
165
+ const el = await mount({roll: 30});
166
+ const pointer = el.shadowRoot!.querySelector('g.roll-pointer');
167
+ expect(pointer).not.toBeNull();
168
+ expect(pointer!.hasAttribute('transform')).toBe(false);
169
+ });
170
+
171
+ it('turns the roll scale with the horizon', async () => {
172
+ const el = await mount({roll: 30});
173
+ expect(watchOf(el).rotation).toBe(-30);
174
+ expect(transformOf(horizonOf(el), 'rotate')).toEqual([-30]);
175
+ });
176
+
177
+ it('keeps the roll scale on the sky side once the pitch passes vertical', async () => {
178
+ // Pitched over the top the vehicle is upside down: the sky is below.
179
+ expect(watchOf(await mount({pitch: 80, roll: -15})).rotation).toBe(15);
180
+ expect(watchOf(await mount({pitch: 172, roll: -15})).rotation).toBe(195);
181
+ expect(watchOf(await mount({pitch: -172, roll: -15})).rotation).toBe(195);
182
+ });
183
+
184
+ it('turns the rest of the face edge with the roll scale', async () => {
185
+ const el = await mount({roll: 30});
186
+ const outline = el.shadowRoot!.querySelector('path.face-outline');
187
+ expect(transformOf(outline, 'rotate')).toEqual([-30]);
188
+ });
189
+
190
+ it('spans the top half with unsigned roll labels', async () => {
191
+ const watch = watchOf(await mount());
192
+ expect(watch.areas.map((a) => [a.startAngle, a.endAngle])).toEqual([
193
+ [-90, 90],
194
+ ]);
195
+ // Left of the top first: the watch counts those angles from 270 up.
196
+ const signed = (angle: number) => (angle > 180 ? angle - 360 : angle);
197
+ const labels = watch.tickmarks
198
+ .filter((t) => t.text !== undefined)
199
+ .sort((a, b) => signed(a.angle) - signed(b.angle))
200
+ .map((t) => t.text);
201
+ expect(labels).toEqual(['90', '45', '0', '45', '90']);
202
+ });
203
+
204
+ it('drops the labels when showLabels is off', async () => {
205
+ const watch = watchOf(await mount({showLabels: false}));
206
+ expect(watch.tickmarks.some((t) => t.text !== undefined)).toBe(false);
207
+ });
208
+ });
@@ -0,0 +1,87 @@
1
+ import type {Meta, StoryObj} from '@storybook/web-components-vite';
2
+ import {ObcAttitude} from './attitude.js';
3
+ import './attitude.js';
4
+ import {widthDecorator} from '../../storybook-util.js';
5
+ import {Priority} from '../types.js';
6
+
7
+ const meta: Meta<typeof ObcAttitude> = {
8
+ title: 'Instruments/Attitude',
9
+ tags: ['autodocs', '6.1', 'experimental'],
10
+ component: 'obc-attitude',
11
+ args: {
12
+ width: 512,
13
+ pitch: 0,
14
+ roll: 0,
15
+ pitchTickInterval: 10,
16
+ showLabels: true,
17
+ priority: Priority.regular,
18
+ },
19
+ argTypes: {
20
+ width: {control: {type: 'range', min: 100, max: 1000, step: 1}},
21
+ pitch: {control: {type: 'range', min: -180, max: 180, step: 0.5}},
22
+ roll: {control: {type: 'range', min: -180, max: 180, step: 0.5}},
23
+ pitchTickInterval: {control: {type: 'range', min: 1, max: 90, step: 1}},
24
+ priority: {control: 'select', options: Object.values(Priority)},
25
+ showLabels: {control: 'boolean'},
26
+ },
27
+ decorators: [widthDecorator],
28
+ } satisfies Meta<ObcAttitude>;
29
+
30
+ export default meta;
31
+ type Story = StoryObj<ObcAttitude>;
32
+
33
+ /** Level, as the design draws it (Figma 20108:142406). */
34
+ export const Default: Story = {
35
+ args: {},
36
+ };
37
+
38
+ export const Enhanced: Story = {
39
+ args: {
40
+ priority: Priority.enhanced,
41
+ },
42
+ };
43
+
44
+ /**
45
+ * Front up and right side down: the horizon drops and tilts to the left, and
46
+ * the roll scale turns with it under the pointer.
47
+ */
48
+ export const PitchAndRoll: Story = {
49
+ args: {
50
+ pitch: 12,
51
+ roll: 25,
52
+ },
53
+ };
54
+
55
+ /**
56
+ * Past half a turn of pitch the ladder shows the inverted horizon, ground on
57
+ * top. The roll scale follows the sky to the lower half, away from the pointer.
58
+ */
59
+ export const Inverted: Story = {
60
+ args: {
61
+ pitch: 172,
62
+ roll: -15,
63
+ },
64
+ };
65
+
66
+ /** One rung is 5°, so the same pitch moves the horizon twice as far. */
67
+ export const FineLadder: Story = {
68
+ args: {
69
+ pitch: 12,
70
+ pitchTickInterval: 5,
71
+ },
72
+ };
73
+
74
+ export const WithoutLabels: Story = {
75
+ args: {
76
+ showLabels: false,
77
+ },
78
+ };
79
+
80
+ /** The roll labels keep their text size, so a small face gives up room to them. */
81
+ export const Small: Story = {
82
+ args: {
83
+ width: 160,
84
+ pitch: 6,
85
+ roll: -10,
86
+ },
87
+ };