@oicl/openbridge-webcomponents-full-bundle 2.1.0-next.5 → 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.
- package/.storybook/vitest.hidden-mount.setup.ts +96 -0
- package/bundle/openbridge-webcomponents.bundle.js +47 -8
- package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
- package/custom-elements.json +65 -3
- package/dist/ar/chart-object-vessel-button/chart-object-vessel-button.d.ts.map +1 -1
- package/dist/ar/chart-object-vessel-button/chart-object-vessel-button.js +1 -1
- package/dist/ar/chart-object-vessel-button/chart-object-vessel-button.js.map +1 -1
- package/dist/building-blocks/chart-line/chart-line-base.css.js +8 -0
- package/dist/building-blocks/chart-line/chart-line-base.css.js.map +1 -1
- package/dist/building-blocks/chart-line/chart-line-base.d.ts +3 -1
- package/dist/building-blocks/chart-line/chart-line-base.d.ts.map +1 -1
- package/dist/building-blocks/chart-line/chart-line-base.js +9 -4
- package/dist/building-blocks/chart-line/chart-line-base.js.map +1 -1
- package/dist/charthelpers/label-threshold.d.ts +7 -2
- package/dist/charthelpers/label-threshold.d.ts.map +1 -1
- package/dist/charthelpers/label-threshold.js +14 -2
- package/dist/charthelpers/label-threshold.js.map +1 -1
- package/dist/navigation-instruments/watch-flat/watch-flat.d.ts +8 -0
- package/dist/navigation-instruments/watch-flat/watch-flat.d.ts.map +1 -1
- package/dist/navigation-instruments/watch-flat/watch-flat.js +17 -1
- package/dist/navigation-instruments/watch-flat/watch-flat.js.map +1 -1
- package/package.json +2 -1
- package/script/compact-ng-exports.d.mts +8 -0
- package/script/compact-ng-exports.mjs +109 -0
- package/script/compact-ng-exports.test.ts +66 -0
- package/src/ar/chart-object-vessel-button/chart-object-vessel-button.ts +3 -1
- package/src/building-blocks/chart-line/chart-line-base.css +8 -0
- package/src/building-blocks/chart-line/chart-line-base.ts +16 -5
- package/src/charthelpers/label-threshold.spec.ts +28 -0
- package/src/charthelpers/label-threshold.ts +16 -3
- package/src/navigation-instruments/rot-linear/rot-linear.spec.ts +36 -0
- package/src/navigation-instruments/watch-flat/watch-flat.spec.ts +76 -0
- package/src/navigation-instruments/watch-flat/watch-flat.ts +22 -1
|
@@ -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
|
-
|
|
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
|
+
});
|
|
@@ -8,9 +8,14 @@ import {
|
|
|
8
8
|
unsafeCSS,
|
|
9
9
|
} from 'lit';
|
|
10
10
|
import {property} from 'lit/decorators.js';
|
|
11
|
+
import {ResizeController} from '@lit-labs/observers/resize-controller.js';
|
|
11
12
|
import compentStyle from './watch-flat.css?inline';
|
|
12
13
|
import {Tickmark, TickmarkStyle, tickmark} from './tickmark-flat.js';
|
|
13
14
|
import {rect} from '../../svghelpers/rectangular.js';
|
|
15
|
+
import {
|
|
16
|
+
measureContainerPx,
|
|
17
|
+
observeInnerBox,
|
|
18
|
+
} from '../../svghelpers/radial-frame.js';
|
|
14
19
|
import {Label} from '../compass-flat/compass-flat.js';
|
|
15
20
|
import {customElement} from '../../decorator.js';
|
|
16
21
|
import {Priority} from '../types.js';
|
|
@@ -113,6 +118,7 @@ export class ObcWatchFlat extends LitElement {
|
|
|
113
118
|
|
|
114
119
|
private _legacyRotationsPerMinute = 0;
|
|
115
120
|
private _rotController?: RateOfTurnController;
|
|
121
|
+
private _resizeController = new ResizeController(this, {});
|
|
116
122
|
|
|
117
123
|
private get _effectiveRpm(): number {
|
|
118
124
|
if (this.rateOfTurnDegreesPerMinute != null) {
|
|
@@ -123,6 +129,16 @@ export class ObcWatchFlat extends LitElement {
|
|
|
123
129
|
return this._legacyRotationsPerMinute;
|
|
124
130
|
}
|
|
125
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Rendered px per user-space unit; the labels divide by it to keep their
|
|
134
|
+
* on-screen size. 1:1 while the strip has no width yet (hidden, or not laid
|
|
135
|
+
* out), until the ResizeController re-renders it.
|
|
136
|
+
*/
|
|
137
|
+
private scaleFor(viewBoxWidth: number): number {
|
|
138
|
+
const scale = measureContainerPx(this).width / viewBoxWidth;
|
|
139
|
+
return Number.isFinite(scale) && scale > 0 ? scale : 1;
|
|
140
|
+
}
|
|
141
|
+
|
|
126
142
|
private get totalHeight(): number {
|
|
127
143
|
return this.bottomBar ? this.height + this.ticksHeight : this.height;
|
|
128
144
|
}
|
|
@@ -390,6 +406,11 @@ export class ObcWatchFlat extends LitElement {
|
|
|
390
406
|
: nothing;
|
|
391
407
|
}
|
|
392
408
|
|
|
409
|
+
override firstUpdated(changed: PropertyValues): void {
|
|
410
|
+
super.firstUpdated(changed);
|
|
411
|
+
observeInnerBox(this._resizeController, this.renderRoot);
|
|
412
|
+
}
|
|
413
|
+
|
|
393
414
|
override updated(changed: PropertyValues): void {
|
|
394
415
|
super.updated(changed);
|
|
395
416
|
const el = this.rotType
|
|
@@ -433,7 +454,7 @@ export class ObcWatchFlat extends LitElement {
|
|
|
433
454
|
const width = (this.width / 2 + this.padding) * 2;
|
|
434
455
|
const th = this.totalHeight;
|
|
435
456
|
const viewBox = `-${width / 2} -${th / 2} ${width} ${th}`;
|
|
436
|
-
const scale = this.
|
|
457
|
+
const scale = this.scaleFor(width);
|
|
437
458
|
|
|
438
459
|
const contentOffsetY = this.bottomBar ? -this.ticksHeight / 2 : 0;
|
|
439
460
|
|