@oicl/openbridge-webcomponents 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- package/.storybook/main.ts +2 -0
- package/.storybook/preview.ts +11 -0
- package/.vscode/launch.json +16 -0
- package/README.md +8 -0
- package/__snapshots__/alert-icon--primary.png +0 -0
- package/__snapshots__/application-alert-button--notification.png +0 -0
- package/__snapshots__/application-alert-button--running.png +0 -0
- package/__snapshots__/application-notification-message--large-single-message.png +0 -0
- package/__snapshots__/application-notification-message--large.png +0 -0
- package/__snapshots__/application-notification-message--primary.png +0 -0
- package/__snapshots__/button-rich-button--bottom-with-boarder.png +0 -0
- package/__snapshots__/button-rich-button--bottom.png +0 -0
- package/__snapshots__/button-rich-button--center.png +0 -0
- package/__snapshots__/button-rich-button--double-line.png +0 -0
- package/__snapshots__/button-rich-button--multi-line.png +0 -0
- package/__snapshots__/button-rich-button--regular-no-icons.png +0 -0
- package/__snapshots__/button-rich-button--regular.png +0 -0
- package/__snapshots__/button-rich-button--single-line.png +0 -0
- package/__snapshots__/button-rich-button--top-with-boarder.png +0 -0
- package/__snapshots__/button-rich-button--top.png +0 -0
- package/__snapshots__/button-rich-button--with-graphic-border.png +0 -0
- package/__snapshots__/button-rich-button--with-graphic.png +0 -0
- package/__snapshots__/button-rich-button--with-status.png +0 -0
- package/__snapshots__/button-vendor-button--primary.png +0 -0
- package/__snapshots__/icons-icon--list.png +0 -0
- package/__snapshots__/icons-icon--use-font-color.png +0 -0
- package/custom-elements.json +2177 -591
- package/dist/components/alert-button/alert-button.css.js +4 -12
- package/dist/components/alert-button/alert-button.css.js.map +1 -1
- package/dist/components/alert-button/alert-button.d.ts +11 -1
- package/dist/components/alert-button/alert-button.d.ts.map +1 -1
- package/dist/components/alert-button/alert-button.js +21 -1
- package/dist/components/alert-button/alert-button.js.map +1 -1
- package/dist/components/alert-icon/alert-icon.d.ts +36 -0
- package/dist/components/alert-icon/alert-icon.d.ts.map +1 -0
- package/dist/components/alert-icon/alert-icon.js +84 -0
- package/dist/components/alert-icon/alert-icon.js.map +1 -0
- package/dist/components/alert-icon/icons/icon-14-alarm-silenced-a.d.ts +2 -0
- package/dist/components/alert-icon/icons/icon-14-alarm-silenced-a.d.ts.map +1 -0
- package/dist/components/alert-icon/icons/icon-14-alarm-silenced-a.js +13 -0
- package/dist/components/alert-icon/icons/icon-14-alarm-silenced-a.js.map +1 -0
- package/dist/components/alert-icon/icons/icon-14-alarm-silenced-b.d.ts +2 -0
- package/dist/components/alert-icon/icons/icon-14-alarm-silenced-b.d.ts.map +1 -0
- package/dist/components/alert-icon/icons/icon-14-alarm-silenced-b.js +20 -0
- package/dist/components/alert-icon/icons/icon-14-alarm-silenced-b.js.map +1 -0
- package/dist/components/alert-icon/icons/icon-14-alarm-unack-a.d.ts +2 -0
- package/dist/components/alert-icon/icons/icon-14-alarm-unack-a.d.ts.map +1 -0
- package/dist/components/alert-icon/icons/icon-14-alarm-unack-a.js +12 -0
- package/dist/components/alert-icon/icons/icon-14-alarm-unack-a.js.map +1 -0
- package/dist/components/alert-icon/icons/icon-14-alarm-unack-b.d.ts +2 -0
- package/dist/components/alert-icon/icons/icon-14-alarm-unack-b.d.ts.map +1 -0
- package/dist/components/alert-icon/icons/icon-14-alarm-unack-b.js +19 -0
- package/dist/components/alert-icon/icons/icon-14-alarm-unack-b.js.map +1 -0
- package/dist/components/alert-icon/icons/icon-14-warning-unack-a.d.ts +2 -0
- package/dist/components/alert-icon/icons/icon-14-warning-unack-a.d.ts.map +1 -0
- package/dist/components/alert-icon/icons/icon-14-warning-unack-a.js +12 -0
- package/dist/components/alert-icon/icons/icon-14-warning-unack-a.js.map +1 -0
- package/dist/components/alert-icon/icons/icon-14-warning-unack-b.d.ts +2 -0
- package/dist/components/alert-icon/icons/icon-14-warning-unack-b.d.ts.map +1 -0
- package/dist/components/alert-icon/icons/icon-14-warning-unack-b.js +12 -0
- package/dist/components/alert-icon/icons/icon-14-warning-unack-b.js.map +1 -0
- package/dist/components/alert-topbar-element/alert-topbar-element.d.ts +13 -0
- package/dist/components/alert-topbar-element/alert-topbar-element.d.ts.map +1 -1
- package/dist/components/alert-topbar-element/alert-topbar-element.js +10 -0
- package/dist/components/alert-topbar-element/alert-topbar-element.js.map +1 -1
- package/dist/components/rich-button/rich-button.css.js +182 -0
- package/dist/components/rich-button/rich-button.css.js.map +1 -0
- package/dist/components/rich-button/rich-button.d.ts +32 -0
- package/dist/components/rich-button/rich-button.d.ts.map +1 -0
- package/dist/components/rich-button/rich-button.js +113 -0
- package/dist/components/rich-button/rich-button.js.map +1 -0
- package/dist/components/vendor-button/vendor-button.css.js +48 -0
- package/dist/components/vendor-button/vendor-button.css.js.map +1 -0
- package/dist/components/vendor-button/vendor-button.d.ts +13 -0
- package/dist/components/vendor-button/vendor-button.d.ts.map +1 -0
- package/dist/components/vendor-button/vendor-button.js +42 -0
- package/dist/components/vendor-button/vendor-button.js.map +1 -0
- package/dist/icons/{icon-07-target-radar.d.ts → icon-01-content-copy.d.ts} +3 -3
- package/dist/icons/{icon-07-target-radar.d.ts.map → icon-01-content-copy.d.ts.map} +1 -1
- package/dist/icons/{icon-07-target-radar.js → icon-01-content-copy.js} +10 -10
- package/dist/icons/icon-01-content-copy.js.map +1 -0
- package/dist/icons/{icon-07-target-ias-selected.d.ts → icon-01-content-cut.d.ts} +3 -3
- package/dist/icons/icon-01-content-cut.d.ts.map +1 -0
- package/dist/icons/icon-01-content-cut.js +52 -0
- package/dist/icons/icon-01-content-cut.js.map +1 -0
- package/dist/icons/{icon-07-target-radar-selected.d.ts → icon-01-content-paste.d.ts} +3 -3
- package/dist/icons/icon-01-content-paste.d.ts.map +1 -0
- package/dist/icons/icon-01-content-paste.js +52 -0
- package/dist/icons/icon-01-content-paste.js.map +1 -0
- package/dist/icons/icon-02-dock-bottom.d.ts +14 -0
- package/dist/icons/icon-02-dock-bottom.d.ts.map +1 -0
- package/dist/icons/icon-02-dock-bottom.js +52 -0
- package/dist/icons/icon-02-dock-bottom.js.map +1 -0
- package/dist/icons/{icon-07-target-ias.d.ts → icon-02-dock-left.d.ts} +3 -3
- package/dist/icons/icon-02-dock-left.d.ts.map +1 -0
- package/dist/icons/{icon-07-target-ias.js → icon-02-dock-left.js} +10 -24
- package/dist/icons/icon-02-dock-left.js.map +1 -0
- package/dist/icons/icon-02-dock-right.d.ts +14 -0
- package/dist/icons/icon-02-dock-right.d.ts.map +1 -0
- package/dist/icons/icon-02-dock-right.js +52 -0
- package/dist/icons/icon-02-dock-right.js.map +1 -0
- package/dist/icons/icon-03-license.d.ts +14 -0
- package/dist/icons/icon-03-license.d.ts.map +1 -0
- package/dist/icons/icon-03-license.js +52 -0
- package/dist/icons/icon-03-license.js.map +1 -0
- package/dist/icons/icon-03-star-unchecked.js +1 -1
- package/dist/icons/icon-03-star-unchecked.js.map +1 -1
- package/dist/icons/icon-04-colorcalibrated.d.ts.map +1 -1
- package/dist/icons/icon-04-colorcalibrated.js +2 -14
- package/dist/icons/icon-04-colorcalibrated.js.map +1 -1
- package/dist/icons/icon-07-target-associated-ais-camera.d.ts +14 -0
- package/dist/icons/icon-07-target-associated-ais-camera.d.ts.map +1 -0
- package/dist/icons/icon-07-target-associated-ais-camera.js +54 -0
- package/dist/icons/icon-07-target-associated-ais-camera.js.map +1 -0
- package/dist/icons/icon-07-target-associated-camera-radar.d.ts +14 -0
- package/dist/icons/icon-07-target-associated-camera-radar.d.ts.map +1 -0
- package/dist/icons/icon-07-target-associated-camera-radar.js +52 -0
- package/dist/icons/icon-07-target-associated-camera-radar.js.map +1 -0
- package/dist/icons/icon-07-target-associated-radar-camera.d.ts +14 -0
- package/dist/icons/icon-07-target-associated-radar-camera.d.ts.map +1 -0
- package/dist/icons/icon-07-target-associated-radar-camera.js +54 -0
- package/dist/icons/icon-07-target-associated-radar-camera.js.map +1 -0
- package/dist/icons/icon-07-target-camera.d.ts +14 -0
- package/dist/icons/icon-07-target-camera.d.ts.map +1 -0
- package/dist/icons/icon-07-target-camera.js +52 -0
- package/dist/icons/icon-07-target-camera.js.map +1 -0
- package/dist/icons/icon-08-backward-fast.js +1 -1
- package/dist/icons/icon-08-backward-fast.js.map +1 -1
- package/dist/icons/icon-08-backward-stopped.js +1 -1
- package/dist/icons/icon-08-backward-stopped.js.map +1 -1
- package/dist/icons/icon-08-forward-fast.js +1 -1
- package/dist/icons/icon-08-forward-fast.js.map +1 -1
- package/dist/icons/icon-08-forward-stopped.js +1 -1
- package/dist/icons/icon-08-forward-stopped.js.map +1 -1
- package/dist/icons/icon-08-motor-off-horisontal.js +1 -1
- package/dist/icons/icon-08-motor-off-horisontal.js.map +1 -1
- package/dist/icons/icon-09-switch-horizontal-off-large.js +1 -1
- package/dist/icons/icon-09-switch-horizontal-off-large.js.map +1 -1
- package/dist/icons/icon-09-switch-horizontal-off.js +1 -1
- package/dist/icons/icon-09-switch-horizontal-off.js.map +1 -1
- package/dist/icons/icon-10-autonomous.js +3 -3
- package/dist/icons/icon-10-autonomous.js.map +1 -1
- package/dist/icons/icon-14-alert-rectified.js +1 -1
- package/dist/icons/icon-14-alert-rectified.js.map +1 -1
- package/dist/icons/icon-14-alertheader-aggregated-large.d.ts +14 -0
- package/dist/icons/icon-14-alertheader-aggregated-large.d.ts.map +1 -0
- package/dist/icons/icon-14-alertheader-aggregated-large.js +52 -0
- package/dist/icons/icon-14-alertheader-aggregated-large.js.map +1 -0
- package/dist/icons/icon-14-alertheader-group-large.d.ts +14 -0
- package/dist/icons/icon-14-alertheader-group-large.d.ts.map +1 -0
- package/dist/icons/icon-14-alertheader-group-large.js +54 -0
- package/dist/icons/icon-14-alertheader-group-large.js.map +1 -0
- package/dist/icons/icon-14-exclamationmark.js +4 -4
- package/dist/icons/icon-14-exclamationmark.js.map +1 -1
- package/dist/icons/icon-14-rectified.js +1 -1
- package/dist/icons/icon-14-rectified.js.map +1 -1
- package/dist/icons/icon-18-ais-anchored.js +4 -4
- package/dist/icons/icon-18-ais-anchored.js.map +1 -1
- package/dist/icons/icon-18-ais-notunderway.js +1 -1
- package/dist/icons/icon-18-ais-notunderway.js.map +1 -1
- package/dist/icons/icon-iec-02-ais-target-activated-selected.d.ts +14 -0
- package/dist/icons/icon-iec-02-ais-target-activated-selected.d.ts.map +1 -0
- package/dist/icons/icon-iec-02-ais-target-activated-selected.js +52 -0
- package/dist/icons/icon-iec-02-ais-target-activated-selected.js.map +1 -0
- package/dist/icons/icon-iec-02-ais-target-activated.d.ts +14 -0
- package/dist/icons/icon-iec-02-ais-target-activated.d.ts.map +1 -0
- package/dist/icons/icon-iec-02-ais-target-activated.js +52 -0
- package/dist/icons/icon-iec-02-ais-target-activated.js.map +1 -0
- package/dist/icons/icon-iec-02-associated-target-ais.d.ts +14 -0
- package/dist/icons/icon-iec-02-associated-target-ais.d.ts.map +1 -0
- package/dist/icons/icon-iec-02-associated-target-ais.js +52 -0
- package/dist/icons/icon-iec-02-associated-target-ais.js.map +1 -0
- package/dist/icons/icon-iec-02-associated-target-radar.d.ts +14 -0
- package/dist/icons/icon-iec-02-associated-target-radar.d.ts.map +1 -0
- package/dist/icons/icon-iec-02-associated-target-radar.js +52 -0
- package/dist/icons/icon-iec-02-associated-target-radar.js.map +1 -0
- package/dist/icons/icon-iec-02-radar-target-tracked-selected.d.ts +14 -0
- package/dist/icons/icon-iec-02-radar-target-tracked-selected.d.ts.map +1 -0
- package/dist/icons/icon-iec-02-radar-target-tracked-selected.js +60 -0
- package/dist/icons/icon-iec-02-radar-target-tracked-selected.js.map +1 -0
- package/dist/icons/icon-iec-02-radar-target-tracked.d.ts +14 -0
- package/dist/icons/icon-iec-02-radar-target-tracked.d.ts.map +1 -0
- package/dist/icons/icon-iec-02-radar-target-tracked.js +52 -0
- package/dist/icons/icon-iec-02-radar-target-tracked.js.map +1 -0
- package/dist/icons/index.d.ts +19 -4
- package/dist/icons/index.d.ts.map +1 -1
- package/dist/icons/index.js +19 -4
- package/dist/icons/index.js.map +1 -1
- package/dist/icons/names.d.ts.map +1 -1
- package/dist/icons/names.js +19 -4
- package/dist/icons/names.js.map +1 -1
- package/dist/navigation-instruments/thruster/thruster.d.ts +2 -1
- package/dist/navigation-instruments/thruster/thruster.d.ts.map +1 -1
- package/dist/navigation-instruments/thruster/thruster.js +45 -25
- package/dist/navigation-instruments/thruster/thruster.js.map +1 -1
- package/fix-generated.cjs +3 -0
- package/new-component.ts +7 -8
- package/package.json +6 -3
- package/script/convert-icons.ts +177 -0
- package/script/download-alert-icons.ts +180 -0
- package/script/download-icons.ts +7 -141
- package/src/components/alert-button/alert-button.css +1 -12
- package/src/components/alert-button/alert-button.stories.ts +2 -0
- package/src/components/alert-button/alert-button.ts +29 -4
- package/src/components/alert-icon/alert-icon.stories.ts +35 -0
- package/src/components/alert-icon/alert-icon.ts +75 -0
- package/src/components/alert-icon/icons/icon-14-alarm-silenced-a.ts +9 -0
- package/src/components/alert-icon/icons/icon-14-alarm-silenced-b.ts +16 -0
- package/src/components/alert-icon/icons/icon-14-alarm-unack-a.ts +8 -0
- package/src/components/alert-icon/icons/icon-14-alarm-unack-b.ts +15 -0
- package/src/components/alert-icon/icons/icon-14-warning-unack-a.ts +8 -0
- package/src/components/alert-icon/icons/icon-14-warning-unack-b.ts +8 -0
- package/src/components/alert-topbar-element/alert-topbar-element.stories.ts +4 -0
- package/src/components/alert-topbar-element/alert-topbar-element.ts +17 -0
- package/src/components/notification-message/notification-message.stories.ts +26 -10
- package/src/components/rich-button/rich-button.css +118 -0
- package/src/components/rich-button/rich-button.stories.ts +196 -0
- package/src/components/rich-button/rich-button.ts +95 -0
- package/src/components/vendor-button/vendor-button.css +10 -0
- package/src/components/vendor-button/vendor-button.stories.ts +19 -0
- package/src/components/vendor-button/vendor-button.ts +25 -0
- package/src/icons/icon-01-content-copy.ts +40 -0
- package/src/icons/icon-01-content-cut.ts +40 -0
- package/src/icons/icon-01-content-paste.ts +40 -0
- package/src/icons/icon-02-dock-bottom.ts +40 -0
- package/src/icons/icon-02-dock-left.ts +40 -0
- package/src/icons/icon-02-dock-right.ts +40 -0
- package/src/icons/icon-03-license.ts +40 -0
- package/src/icons/icon-03-star-unchecked.ts +1 -1
- package/src/icons/icon-04-colorcalibrated.ts +2 -14
- package/src/icons/icon-07-target-associated-ais-camera.ts +42 -0
- package/src/icons/icon-07-target-associated-camera-radar.ts +40 -0
- package/src/icons/icon-07-target-associated-radar-camera.ts +42 -0
- package/src/icons/icon-07-target-camera.ts +40 -0
- package/src/icons/icon-08-backward-fast.ts +1 -1
- package/src/icons/icon-08-backward-stopped.ts +1 -1
- package/src/icons/icon-08-forward-fast.ts +1 -1
- package/src/icons/icon-08-forward-stopped.ts +1 -1
- package/src/icons/icon-08-motor-off-horisontal.ts +1 -1
- package/src/icons/icon-09-switch-horizontal-off-large.ts +1 -1
- package/src/icons/icon-09-switch-horizontal-off.ts +1 -1
- package/src/icons/icon-10-autonomous.ts +3 -3
- package/src/icons/icon-14-alert-rectified.ts +1 -1
- package/src/icons/icon-14-alertheader-aggregated-large.ts +40 -0
- package/src/icons/icon-14-alertheader-group-large.ts +42 -0
- package/src/icons/icon-14-exclamationmark.ts +4 -4
- package/src/icons/icon-14-rectified.ts +1 -1
- package/src/icons/icon-18-ais-anchored.ts +4 -4
- package/src/icons/icon-18-ais-notunderway.ts +1 -1
- package/src/icons/icon-iec-02-ais-target-activated-selected.ts +40 -0
- package/src/icons/icon-iec-02-ais-target-activated.ts +40 -0
- package/src/icons/icon-iec-02-associated-target-ais.ts +40 -0
- package/src/icons/icon-iec-02-associated-target-radar.ts +40 -0
- package/src/icons/icon-iec-02-radar-target-tracked-selected.ts +48 -0
- package/src/icons/icon-iec-02-radar-target-tracked.ts +40 -0
- package/src/icons/index.ts +19 -4
- package/src/icons/names.ts +19 -4
- package/src/icons.stories.ts +78 -0
- package/src/navigation-instruments/thruster/thruster.stories.ts +18 -1
- package/src/navigation-instruments/thruster/thruster.ts +43 -27
- package/dist/icons/icon-07-target-ias-selected.d.ts.map +0 -1
- package/dist/icons/icon-07-target-ias-selected.js +0 -60
- package/dist/icons/icon-07-target-ias-selected.js.map +0 -1
- package/dist/icons/icon-07-target-ias.d.ts.map +0 -1
- package/dist/icons/icon-07-target-ias.js.map +0 -1
- package/dist/icons/icon-07-target-radar-selected.d.ts.map +0 -1
- package/dist/icons/icon-07-target-radar-selected.js +0 -60
- package/dist/icons/icon-07-target-radar-selected.js.map +0 -1
- package/dist/icons/icon-07-target-radar.js.map +0 -1
- package/src/icons/icon-07-target-ias-selected.ts +0 -48
- package/src/icons/icon-07-target-ias.ts +0 -54
- package/src/icons/icon-07-target-radar-selected.ts +0 -48
- package/src/icons/icon-07-target-radar.ts +0 -40
@@ -1,4 +1,4 @@
|
|
1
|
-
import { LitElement, svg } from "lit";
|
1
|
+
import { css, LitElement, html, svg } from "lit";
|
2
2
|
import { property, customElement } from "lit/decorators.js";
|
3
3
|
import { Size, InstrumentState } from "../types.js";
|
4
4
|
var __defProp = Object.defineProperty;
|
@@ -25,13 +25,26 @@ let ObcThruster = class extends LitElement {
|
|
25
25
|
this.off = false;
|
26
26
|
}
|
27
27
|
render() {
|
28
|
-
return
|
28
|
+
return html`<div class="container">
|
29
|
+
${thruster(this.thrust, this.setpoint, this.state, {
|
29
30
|
atSetpoint: this.atSetpoint,
|
30
31
|
tunnel: this.tunnel,
|
31
32
|
setpointAtZero: this.setpointAtZero
|
32
|
-
})
|
33
|
+
})}
|
34
|
+
</div>`;
|
33
35
|
}
|
34
36
|
};
|
37
|
+
ObcThruster.styles = css`
|
38
|
+
.container {
|
39
|
+
height: 100%;
|
40
|
+
width: 100%;
|
41
|
+
}
|
42
|
+
|
43
|
+
.container > svg {
|
44
|
+
height: 100%;
|
45
|
+
width: 100%;
|
46
|
+
}
|
47
|
+
`;
|
35
48
|
__decorateClass([
|
36
49
|
property({ type: String })
|
37
50
|
], ObcThruster.prototype, "size", 2);
|
@@ -150,35 +163,42 @@ function thruster(thrust, setpoint, state, options) {
|
|
150
163
|
const centerLine = svg`
|
151
164
|
<rect x="-32" y="-2" width="64" height="4" fill=${zeroLineColor} stroke=${zeroLineColor}/>
|
152
165
|
`;
|
153
|
-
const thrusterSvg =
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
166
|
+
const thrusterSvg = [
|
167
|
+
thrusterTop(
|
168
|
+
Math.max(thrust, 0),
|
169
|
+
{ box: boxColor, container: containerBackgroundColor },
|
170
|
+
hideTicks
|
171
|
+
),
|
172
|
+
thrusterBottom(
|
173
|
+
Math.max(-thrust, 0),
|
174
|
+
{ box: boxColor, container: containerBackgroundColor },
|
175
|
+
hideTicks
|
176
|
+
),
|
177
|
+
centerLine
|
178
|
+
];
|
179
|
+
if (setpoint !== void 0) {
|
180
|
+
thrusterSvg.push(
|
181
|
+
setpointSvg(setpoint, options.setpointAtZero, {
|
182
|
+
fill: setPointColor,
|
183
|
+
stroke: "var(--border-silhouette-color)"
|
184
|
+
})
|
185
|
+
);
|
186
|
+
}
|
173
187
|
if (options.tunnel) {
|
174
188
|
return svg`
|
175
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-160 -64 320 128" x="-160" y="-64"
|
189
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-160 -64 320 128" x="-160" y="-64">
|
176
190
|
<g transform="rotate(90)">
|
177
191
|
${thrusterSvg}
|
178
192
|
</g>
|
179
193
|
</svg>`;
|
194
|
+
} else {
|
195
|
+
thrusterSvg.push(arrowTop(arrowColor));
|
196
|
+
return svg`
|
197
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-64 -160 128 320" x="-64" y="-160">
|
198
|
+
${thrusterSvg}
|
199
|
+
</svg>
|
200
|
+
`;
|
180
201
|
}
|
181
|
-
return thrusterSvg;
|
182
202
|
}
|
183
203
|
export {
|
184
204
|
ObcThruster,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"thruster.js","sources":["../../../src/navigation-instruments/thruster/thruster.ts"],"sourcesContent":["import {LitElement, svg} from 'lit';\nimport {customElement, property} from 'lit/decorators.js';\nimport {Size, InstrumentState} from '../types';\n\n/**\n * @element obc-thruster\n *\n * @prop {Size} size - The size of the thruster\n * @prop {number} thrust - The thrust of the thruster in percent (-100 - +100)\n */\n@customElement('obc-thruster')\nexport class ObcThruster extends LitElement {\n @property({type: String}) size: Size = Size.medium;\n @property({type: Number}) thrust: number = 0;\n @property({type: Number}) setpoint: number | undefined;\n @property({type: Boolean, attribute: 'at-setpoint'}) atSetpoint: boolean =\n false;\n @property({type: Boolean, attribute: 'setpoint-at-zero'})\n setpointAtZero: boolean = false;\n @property({type: String}) state: InstrumentState = InstrumentState.inCommand;\n @property({type: Boolean}) tunnel: boolean = false;\n @property({type: Boolean}) loading: boolean = false;\n @property({type: Boolean}) off: boolean = false;\n\n override render() {\n return thruster(this.thrust, this.setpoint, this.state, {\n atSetpoint: this.atSetpoint,\n tunnel: this.tunnel,\n setpointAtZero: this.setpointAtZero,\n });\n }\n}\nconst containerHeight = 134;\n\nfunction thrusterTop(\n value: number,\n colors: {box: string; container: string},\n hideTicks: boolean\n) {\n const container = svg`\n <path transform=\"translate(-33 -137)\" d=\"M1 9C1 4.58172 4.58172 1 9 1H57C61.4183 1 65 4.58172 65 9V135H1V9Z\" fill=${colors.container} stroke=\"var(--instrument-frame-tertiary-color)\" vector-effect=\"non-scaling-stroke\"/>\n `;\n const track = svg`<rect width=\"32\" height=\"134\" x=\"-16\" y=\"-136\" fill=\"var(--instrument-frame-secondary-color)\" stroke=\"var(--instrument-frame-tertiary-color)\" vector-effect=\"non-scaling-stroke\"/>`;\n\n const tickmarks = [];\n\n const nTicks = 4;\n const delta = containerHeight / nTicks;\n if (!hideTicks) {\n for (let i = 1; i < nTicks; i++) {\n tickmarks.push(\n svg`<line x1=\"-20\" x2=\"-28\" y1=${-i * delta - 2} y2=${\n -i * delta - 2\n } stroke=\"var(--instrument-frame-tertiary-color)\" stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`\n );\n tickmarks.push(\n svg`<line x1=\"20\" x2=\"28\" y1=${-i * delta - 2} y2=${\n -i * delta - 2\n } stroke=\"var(--instrument-frame-tertiary-color)\" stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`\n );\n }\n }\n\n const barHeight = (134 * value) / 100;\n const barY = -136 + 134 - barHeight;\n const bar = svg`<rect width=\"32\" height=${barHeight} x=\"-16\" y=${barY} fill=${colors.box} stroke=${colors.box} vector-effect=\"non-scaling-stroke\"/>`;\n\n return [container, track, tickmarks, bar];\n}\n\nfunction thrusterBottom(\n value: number,\n colors: {box: string; container: string},\n hideTicks: boolean\n) {\n const container = svg`\n <g transform=\"rotate(180)\">\n ${thrusterTop(value, colors, hideTicks)}\n </g>\n `;\n return container;\n}\n\nfunction arrowTop(arrowColor: string) {\n return svg`\n<path transform=\"translate(-15 -156)\" d=\"M0.707007 14.2929L14.9999 0L29.2928 14.2929C29.9228 14.9229 29.4766 16 28.5857 16H1.41412C0.523211 16 0.0770419 14.9229 0.707007 14.2929Z\" fill=${arrowColor}/>`;\n}\n\nfunction setpointSvg(\n value: number,\n setpointAtZero: boolean,\n colors: {fill: string; stroke: string}\n) {\n const y =\n -12 +\n -(setpointAtZero\n ? 0\n : Math.sign(value) * ((containerHeight * Math.abs(value)) / 100 + 2));\n return svg`\n <g transform=\"translate(-40 ${y})\">\n <path d=\"M59.4001 11.1999C59.1483 11.3887 59 11.6852 59 12C59 12.3148 59.1483 12.6113 59.4001 12.8001L72.2001 22.3966C74.1773 23.879 77 22.4692 77 19.9971L77 4.0029C77 1.53076 74.1773 0.121035 72.2001 1.60338L59.4001 11.1999Z\" fill=${colors.fill} stroke=${colors.stroke} stroke-width=\"2\" stroke-linejoin=\"round\" vector-effect=\"non-scaling-stroke\"/>\n <path d=\"M20.5999 12.8001C20.8517 12.6113 21 12.3148 21 12C21 11.6852 20.8517 11.3887 20.5999 11.1999L7.79986 1.60338C5.82268 0.121036 3 1.53075 3 4.0029L3 19.9971C3 22.4692 5.82268 23.879 7.79986 22.3966L20.5999 12.8001Z\" fill=${colors.fill} stroke=${colors.stroke} stroke-width=\"2\" stroke-linejoin=\"round\" vector-effect=\"non-scaling-stroke\"/>\n </g>\n`;\n}\n\nexport function thruster(\n thrust: number,\n setpoint: number | undefined,\n state: InstrumentState,\n options: {atSetpoint: boolean; tunnel: boolean; setpointAtZero: boolean}\n) {\n let boxColor = 'var(--instrument-enhanced-secondary-color)';\n let setPointColor = boxColor;\n let arrowColor = 'var(--instrument-tick-mark-primary-color)';\n let containerBackgroundColor = 'var(--instrument-frame-primary-color)';\n let zeroLineColor = 'var(--instrument-enhanced-secondary-color)';\n let hideTicks = false;\n if (options.atSetpoint) {\n setPointColor = 'var(--instrument-frame-tertiary-color)';\n }\n if (state === InstrumentState.active) {\n boxColor = 'var(--instrument-regular-secondary-color)';\n zeroLineColor = 'var(--instrument-regular-secondary-color)';\n setPointColor = boxColor;\n arrowColor = 'var(--instrument-regular-secondary-color)';\n if (options.atSetpoint) {\n setPointColor = 'var(--instrument-frame-tertiary-color)';\n }\n } else if (state === InstrumentState.loading) {\n boxColor = 'transparent';\n setPointColor = 'var(--instrument-frame-tertiary-color)';\n zeroLineColor = 'var(--instrument-frame-tertiary-color)';\n arrowColor = 'var(--instrument-regular-secondary-color)';\n thrust = 0;\n hideTicks = true;\n if (setpoint !== undefined) {\n setpoint = 0;\n }\n } else if (state === InstrumentState.off) {\n boxColor = 'transparent';\n setPointColor = 'var(--instrument-frame-tertiary-color)';\n arrowColor = 'var(--instrument-frame-tertiary-color)';\n zeroLineColor = 'var(--instrument-frame-tertiary-color)';\n thrust = 0;\n hideTicks = true;\n containerBackgroundColor = 'transparent';\n if (setpoint !== undefined) {\n setpoint = 0;\n }\n }\n\n const centerLine = svg`\n <rect x=\"-32\" y=\"-2\" width=\"64\" height=\"4\" fill=${zeroLineColor} stroke=${zeroLineColor}/>\n `;\n\n const thrusterSvg = svg`\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"-64 -160 128 320\" x=\"-64\" y=\"-160\" width=\"128\" height=\"320\">\n ${thrusterTop(\n Math.max(thrust, 0),\n {box: boxColor, container: containerBackgroundColor},\n hideTicks\n )}\n ${thrusterBottom(\n Math.max(-thrust, 0),\n {box: boxColor, container: containerBackgroundColor},\n hideTicks\n )}\n ${centerLine}\n ${\n setpoint !== undefined\n ? setpointSvg(setpoint, options.setpointAtZero, {\n fill: setPointColor,\n stroke: 'var(--border-silhouette-color)',\n })\n : null\n }\n ${options.tunnel ? null : arrowTop(arrowColor)}\n </svg>\n `;\n\n if (options.tunnel) {\n return svg`\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"-160 -64 320 128\" x=\"-160\" y=\"-64\" width=\"320\" height=\"128\">\n <g transform=\"rotate(90)\">\n ${thrusterSvg}\n </g>\n </svg>`;\n }\n\n return thrusterSvg;\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'obc-thruster': ObcThruster;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAWa,IAAA,cAAN,cAA0B,WAAW;AAAA,EAArC,cAAA;AAAA,UAAA,GAAA,SAAA;AACqB,SAAA,OAAa,KAAK;AACD,SAAA,SAAA;AAGzC,SAAA,aAAA;AAEwB,SAAA,iBAAA;AACA,SAAA,QAAyB,gBAAgB;AACtB,SAAA,SAAA;AACC,SAAA,UAAA;AACJ,SAAA,MAAA;AAAA,EAAA;AAAA,EAEjC,SAAS;AAChB,WAAO,SAAS,KAAK,QAAQ,KAAK,UAAU,KAAK,OAAO;AAAA,MACtD,YAAY,KAAK;AAAA,MACjB,QAAQ,KAAK;AAAA,MACb,gBAAgB,KAAK;AAAA,IAAA,CACtB;AAAA,EACH;AACF;AAnB4B,gBAAA;AAAA,EAAzB,SAAS,EAAC,MAAM,QAAO;AAAA,GADb,YACe,WAAA,QAAA,CAAA;AACA,gBAAA;AAAA,EAAzB,SAAS,EAAC,MAAM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AACG,gBAAA;AACe,+BAAA;AAC3B,QAAI,aAAa,QAAW;AACf,iBAAA;AAAA,IACb;AAAA,EACF;AAEA,QAAM,aAAa;AAAA,sDACiC,aAAa,WAAW,aAAa;AAAA;AAGzF,QAAM,cAAc;AAAA;AAAA,MAEhB;AAAA,IACA,KAAK,IAAI,QAAQ,CAAC;AAAA,IAClB,EAAC,KAAK,UAAU,WAAW,yBAAwB;AAAA,IACnD;AAAA,EAAA,CACD;AAAA,MACC;AAAA,IACA,KAAK,IAAI,CAAC,QAAQ,CAAC;AAAA,IACnB,EAAC,KAAK,UAAU,WAAW,yBAAwB;AAAA,IACnD;AAAA,EAAA,CACD;AAAA,MACC,UAAU;AAAA,MAEV,aAAa,SACT,YAAY,UAAU,QAAQ,gBAAgB;AAAA,IAC5C,MAAM;AAAA,IACN,QAAQ;AAAA,EACT,CAAA,IACD,IACN;AAAA,MACE,QAAQ,SAAS,OAAO,SAAS,UAAU,CAAC;AAAA;AAAA;AAIhD,MAAI,QAAQ,QAAQ;AACX,WAAA;AAAA;AAAA;AAAA,YAGC,WAAW;AAAA;AAAA;AAAA,EAGrB;AAEO,SAAA;AACT;"}
|
1
|
+
{"version":3,"file":"thruster.js","sources":["../../../src/navigation-instruments/thruster/thruster.ts"],"sourcesContent":["import {LitElement, svg, html, css} from 'lit';\nimport {customElement, property} from 'lit/decorators.js';\nimport {Size, InstrumentState} from '../types';\n\n/**\n * @element obc-thruster\n *\n * @prop {Size} size - The size of the thruster\n * @prop {number} thrust - The thrust of the thruster in percent (-100 - +100)\n */\n@customElement('obc-thruster')\nexport class ObcThruster extends LitElement {\n @property({type: String}) size: Size = Size.medium;\n @property({type: Number}) thrust: number = 0;\n @property({type: Number}) setpoint: number | undefined;\n @property({type: Boolean, attribute: 'at-setpoint'}) atSetpoint: boolean =\n false;\n @property({type: Boolean, attribute: 'setpoint-at-zero'})\n setpointAtZero: boolean = false;\n @property({type: String}) state: InstrumentState = InstrumentState.inCommand;\n @property({type: Boolean}) tunnel: boolean = false;\n @property({type: Boolean}) loading: boolean = false;\n @property({type: Boolean}) off: boolean = false;\n\n override render() {\n return html`<div class=\"container\">\n ${thruster(this.thrust, this.setpoint, this.state, {\n atSetpoint: this.atSetpoint,\n tunnel: this.tunnel,\n setpointAtZero: this.setpointAtZero,\n })}\n </div>`;\n }\n\n static override styles = css`\n .container {\n height: 100%;\n width: 100%;\n }\n\n .container > svg {\n height: 100%;\n width: 100%;\n }\n `;\n}\nconst containerHeight = 134;\n\nfunction thrusterTop(\n value: number,\n colors: {box: string; container: string},\n hideTicks: boolean\n) {\n const container = svg`\n <path transform=\"translate(-33 -137)\" d=\"M1 9C1 4.58172 4.58172 1 9 1H57C61.4183 1 65 4.58172 65 9V135H1V9Z\" fill=${colors.container} stroke=\"var(--instrument-frame-tertiary-color)\" vector-effect=\"non-scaling-stroke\"/>\n `;\n const track = svg`<rect width=\"32\" height=\"134\" x=\"-16\" y=\"-136\" fill=\"var(--instrument-frame-secondary-color)\" stroke=\"var(--instrument-frame-tertiary-color)\" vector-effect=\"non-scaling-stroke\"/>`;\n\n const tickmarks = [];\n\n const nTicks = 4;\n const delta = containerHeight / nTicks;\n if (!hideTicks) {\n for (let i = 1; i < nTicks; i++) {\n tickmarks.push(\n svg`<line x1=\"-20\" x2=\"-28\" y1=${-i * delta - 2} y2=${\n -i * delta - 2\n } stroke=\"var(--instrument-frame-tertiary-color)\" stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`\n );\n tickmarks.push(\n svg`<line x1=\"20\" x2=\"28\" y1=${-i * delta - 2} y2=${\n -i * delta - 2\n } stroke=\"var(--instrument-frame-tertiary-color)\" stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`\n );\n }\n }\n\n const barHeight = (134 * value) / 100;\n const barY = -136 + 134 - barHeight;\n const bar = svg`<rect width=\"32\" height=${barHeight} x=\"-16\" y=${barY} fill=${colors.box} stroke=${colors.box} vector-effect=\"non-scaling-stroke\"/>`;\n\n return [container, track, tickmarks, bar];\n}\n\nfunction thrusterBottom(\n value: number,\n colors: {box: string; container: string},\n hideTicks: boolean\n) {\n const container = svg`\n <g transform=\"rotate(180)\">\n ${thrusterTop(value, colors, hideTicks)}\n </g>\n `;\n return container;\n}\n\nfunction arrowTop(arrowColor: string) {\n return svg`\n<path transform=\"translate(-15 -156)\" d=\"M0.707007 14.2929L14.9999 0L29.2928 14.2929C29.9228 14.9229 29.4766 16 28.5857 16H1.41412C0.523211 16 0.0770419 14.9229 0.707007 14.2929Z\" fill=${arrowColor}/>`;\n}\n\nfunction setpointSvg(\n value: number,\n setpointAtZero: boolean,\n colors: {fill: string; stroke: string}\n) {\n const y =\n -12 +\n -(setpointAtZero\n ? 0\n : Math.sign(value) * ((containerHeight * Math.abs(value)) / 100 + 2));\n return svg`\n <g transform=\"translate(-40 ${y})\">\n <path d=\"M59.4001 11.1999C59.1483 11.3887 59 11.6852 59 12C59 12.3148 59.1483 12.6113 59.4001 12.8001L72.2001 22.3966C74.1773 23.879 77 22.4692 77 19.9971L77 4.0029C77 1.53076 74.1773 0.121035 72.2001 1.60338L59.4001 11.1999Z\" fill=${colors.fill} stroke=${colors.stroke} stroke-width=\"2\" stroke-linejoin=\"round\" vector-effect=\"non-scaling-stroke\"/>\n <path d=\"M20.5999 12.8001C20.8517 12.6113 21 12.3148 21 12C21 11.6852 20.8517 11.3887 20.5999 11.1999L7.79986 1.60338C5.82268 0.121036 3 1.53075 3 4.0029L3 19.9971C3 22.4692 5.82268 23.879 7.79986 22.3966L20.5999 12.8001Z\" fill=${colors.fill} stroke=${colors.stroke} stroke-width=\"2\" stroke-linejoin=\"round\" vector-effect=\"non-scaling-stroke\"/>\n </g>\n`;\n}\n\nexport function thruster(\n thrust: number,\n setpoint: number | undefined,\n state: InstrumentState,\n options: {atSetpoint: boolean; tunnel: boolean; setpointAtZero: boolean}\n) {\n let boxColor = 'var(--instrument-enhanced-secondary-color)';\n let setPointColor = boxColor;\n let arrowColor = 'var(--instrument-tick-mark-primary-color)';\n let containerBackgroundColor = 'var(--instrument-frame-primary-color)';\n let zeroLineColor = 'var(--instrument-enhanced-secondary-color)';\n let hideTicks = false;\n if (options.atSetpoint) {\n setPointColor = 'var(--instrument-frame-tertiary-color)';\n }\n if (state === InstrumentState.active) {\n boxColor = 'var(--instrument-regular-secondary-color)';\n zeroLineColor = 'var(--instrument-regular-secondary-color)';\n setPointColor = boxColor;\n arrowColor = 'var(--instrument-regular-secondary-color)';\n if (options.atSetpoint) {\n setPointColor = 'var(--instrument-frame-tertiary-color)';\n }\n } else if (state === InstrumentState.loading) {\n boxColor = 'transparent';\n setPointColor = 'var(--instrument-frame-tertiary-color)';\n zeroLineColor = 'var(--instrument-frame-tertiary-color)';\n arrowColor = 'var(--instrument-regular-secondary-color)';\n thrust = 0;\n hideTicks = true;\n if (setpoint !== undefined) {\n setpoint = 0;\n }\n } else if (state === InstrumentState.off) {\n boxColor = 'transparent';\n setPointColor = 'var(--instrument-frame-tertiary-color)';\n arrowColor = 'var(--instrument-frame-tertiary-color)';\n zeroLineColor = 'var(--instrument-frame-tertiary-color)';\n thrust = 0;\n hideTicks = true;\n containerBackgroundColor = 'transparent';\n if (setpoint !== undefined) {\n setpoint = 0;\n }\n }\n\n const centerLine = svg`\n <rect x=\"-32\" y=\"-2\" width=\"64\" height=\"4\" fill=${zeroLineColor} stroke=${zeroLineColor}/>\n `;\n\n const thrusterSvg = [\n thrusterTop(\n Math.max(thrust, 0),\n {box: boxColor, container: containerBackgroundColor},\n hideTicks\n ),\n thrusterBottom(\n Math.max(-thrust, 0),\n {box: boxColor, container: containerBackgroundColor},\n hideTicks\n ),\n centerLine,\n ];\n if (setpoint !== undefined) {\n thrusterSvg.push(\n setpointSvg(setpoint, options.setpointAtZero, {\n fill: setPointColor,\n stroke: 'var(--border-silhouette-color)',\n })\n );\n }\n\n if (options.tunnel) {\n return svg`\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"-160 -64 320 128\" x=\"-160\" y=\"-64\">\n <g transform=\"rotate(90)\">\n ${thrusterSvg}\n </g>\n </svg>`;\n } else {\n thrusterSvg.push(arrowTop(arrowColor));\n return svg`\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"-64 -160 128 320\" x=\"-64\" y=\"-160\">\n ${thrusterSvg}\n </svg>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'obc-thruster': ObcThruster;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAWa,IAAA,cAAN,cAA0B,WAAW;AAAA,EAArC,cAAA;AAAA,UAAA,GAAA,SAAA;AACqB,SAAA,OAAa,KAAK;AACD,SAAA,SAAA;AAGzC,SAAA,aAAA;AAEwB,SAAA,iBAAA;AACA,SAAA,QAAyB,gBAAgB;AACtB,SAAA,SAAA;AACC,SAAA,UAAA;AACJ,SAAA,MAAA;AAAA,EAAA;AAAA,EAEjC,SAAS;AACT,WAAA;AAAA,QACH,SAAS,KAAK,QAAQ,KAAK,UAAU,KAAK,OAAO;AAAA,MACjD,YAAY,KAAK;AAAA,MACjB,QAAQ,KAAK;AAAA,MACb,gBAAgB,KAAK;AAAA,IAAA,CACtB,CAAC;AAAA;AAAA,EAEN;AAaF;AAlCa,YAuBK,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAtBC,gBAAA;AAAA,EAAzB,SAAS,EAAC,MAAM,QAAO;AAAA,GADb,YACe,WAAA,QAAA,CAAA;AACA,gBAAA;AAAA,EAAzB,SAAS,EAAC,MAAM,QAAO;AAAA,GAFb,YAEe,WAAA,UAAA,CAAA;AACA,gBAAA;AAAA,EAAzB,SAAS,EAAC,MAAM,QAAO;AAAA,GAHb,YAGe,WAAA,YAAA,CAAA;AAC2B,gBAAA;AAAA,EAApD,SAAS,EAAC,MAAM,SAAS,WAAW,eAAc;AAAA,GAJxC,YAI0C,WAAA,cAAA,CAAA;AAGrD,gBAAA;AAAA,EADC,SAAS,EAAC,MAAM,SAAS,WAA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;AAAA,MACE,KAAK,IAAI,CAAC,QAAQ,CAAC;AAAA,MACnB,EAAC,KAAK,UAAU,WAAW,yBAAwB;AAAA,MACnD;AAAA,IACF;AAAA,IACA;AAAA,EAAA;AAEF,MAAI,aAAa,QAAW;AACd,gBAAA;AAAA,MACV,YAAY,UAAU,QAAQ,gBAAgB;AAAA,QAC5C,MAAM;AAAA,QACN,QAAQ;AAAA,MAAA,CACT;AAAA,IAAA;AAAA,EAEL;AAEA,MAAI,QAAQ,QAAQ;AACX,WAAA;AAAA;AAAA;AAAA,YAGC,WAAW;AAAA;AAAA;AAAA,EAAA,OAGd;AACO,gBAAA,KAAK,SAAS,UAAU,CAAC;AAC9B,WAAA;AAAA;AAAA,QAEH,WAAW;AAAA;AAAA;AAAA,EAGjB;AACF;"}
|
package/fix-generated.cjs
CHANGED
@@ -20,6 +20,8 @@ function addRepositoryToPackageJsonVue() {
|
|
20
20
|
url: 'git+https://github.com/Ocean-Industries-Concept-Lab/openbridge-webcomponents.git',
|
21
21
|
directory: 'packages/openbridge-webcomponents-vue',
|
22
22
|
};
|
23
|
+
// add license
|
24
|
+
packageJson.license = 'Apache-2.0';
|
23
25
|
fs.writeFileSync(
|
24
26
|
'../openbridge-webcomponents-vue/package.json',
|
25
27
|
JSON.stringify(packageJson, null, 2)
|
@@ -33,6 +35,7 @@ function addRepositoryToPackageJsonReact() {
|
|
33
35
|
url: 'git+https://github.com/Ocean-Industries-Concept-Lab/openbridge-webcomponents.git',
|
34
36
|
directory: 'packages/openbridge-webcomponents-react',
|
35
37
|
};
|
38
|
+
packageJson.license = 'Apache-2.0';
|
36
39
|
fs.writeFileSync(
|
37
40
|
'../openbridge-webcomponents-react/package.json',
|
38
41
|
JSON.stringify(packageJson, null, 2)
|
package/new-component.ts
CHANGED
@@ -29,7 +29,7 @@ const files = await multiselect('Create files', {
|
|
29
29
|
// Convert name to kebab-case
|
30
30
|
const componentName = name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
31
31
|
|
32
|
-
const parentDir = componentType
|
32
|
+
const parentDir = componentType.includes('ui')
|
33
33
|
? 'components'
|
34
34
|
: 'navigation-instruments';
|
35
35
|
const dir = path.join('src', parentDir, componentName);
|
@@ -38,14 +38,13 @@ fs.mkdirSync(dir);
|
|
38
38
|
|
39
39
|
// Create files
|
40
40
|
if (files.includes('lit')) {
|
41
|
+
const hasCss = files.includes('css');
|
41
42
|
const litFile = path.join(dir, `${componentName}.ts`);
|
42
|
-
const content = `import { LitElement, html
|
43
|
+
const content = `import { LitElement, html${
|
44
|
+
hasCss ? `, unsafeCSS ` : ` `
|
45
|
+
}} from 'lit'
|
43
46
|
import { customElement } from 'lit/decorators.js'
|
44
|
-
${
|
45
|
-
files.includes('css')
|
46
|
-
? `import compentStyle from "./${componentName}.style";`
|
47
|
-
: ''
|
48
|
-
}
|
47
|
+
${hasCss ? `import compentStyle from "./${componentName}.css?inline";` : ''}
|
49
48
|
|
50
49
|
@customElement('obc-${componentName}')
|
51
50
|
export class Obc${name} extends LitElement {
|
@@ -57,7 +56,7 @@ export class Obc${name} extends LitElement {
|
|
57
56
|
\`
|
58
57
|
}
|
59
58
|
|
60
|
-
${
|
59
|
+
${hasCss ? `static override styles = unsafeCSS(compentStyle);` : ''}
|
61
60
|
}
|
62
61
|
|
63
62
|
declare global {
|
package/package.json
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "@oicl/openbridge-webcomponents",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.8",
|
4
4
|
"type": "module",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
7
|
-
"url": "https://github.com/Ocean-Industries-Concept-Lab/openbridge-webcomponents.git",
|
7
|
+
"url": "git+https://github.com/Ocean-Industries-Concept-Lab/openbridge-webcomponents.git",
|
8
8
|
"directory": "packages/openbridge-webcomponents"
|
9
9
|
},
|
10
|
+
"license": "Apache-2.0",
|
10
11
|
"scripts": {
|
11
12
|
"build": "yarn run typecheck && yarn run build:ts && yarn run analyze && yarn run build:wrappers",
|
12
13
|
"build:ts": "vite build",
|
@@ -40,10 +41,13 @@
|
|
40
41
|
"@lit-labs/gen-wrapper-vue": "^0.3.2",
|
41
42
|
"@open-wc/lit-helpers": "^0.6.0",
|
42
43
|
"@storybook/addon-essentials": "^7.6.7",
|
44
|
+
"@storybook/addon-interactions": "^7.6.17",
|
43
45
|
"@storybook/addon-links": "^7.6.7",
|
46
|
+
"@storybook/addon-storysource": "^7.6.17",
|
44
47
|
"@storybook/addon-themes": "^7.6.7",
|
45
48
|
"@storybook/blocks": "^7.6.7",
|
46
49
|
"@storybook/test-runner": "^0.16.0",
|
50
|
+
"@storybook/testing-library": "^0.2.2",
|
47
51
|
"@storybook/web-components": "^7.6.7",
|
48
52
|
"@storybook/web-components-vite": "^7.6.7",
|
49
53
|
"@topcli/prompts": "^1.8.0",
|
@@ -74,7 +78,6 @@
|
|
74
78
|
"vite-plugin-dts": "^3.6.3",
|
75
79
|
"xmldom": "^0.6.0"
|
76
80
|
},
|
77
|
-
"readme": "README.md",
|
78
81
|
"types": "./dist/index.d.ts",
|
79
82
|
"customElements": "custom-elements.json"
|
80
83
|
}
|
@@ -0,0 +1,177 @@
|
|
1
|
+
import * as Figma from 'figma-api';
|
2
|
+
import * as dotenv from 'dotenv';
|
3
|
+
|
4
|
+
dotenv.config();
|
5
|
+
|
6
|
+
export interface IconRef {
|
7
|
+
name: string;
|
8
|
+
id: string;
|
9
|
+
javascriptName: string;
|
10
|
+
styles: {[colorCode: string]: {cssClass: string}};
|
11
|
+
}
|
12
|
+
|
13
|
+
export function getSingleColorIcon(imageData: string, icon: IconRef): string {
|
14
|
+
// replace fill color with currentColor
|
15
|
+
const fillRegex = /fill="[^"]+"/g;
|
16
|
+
const replace = 'fill="currentColor"';
|
17
|
+
let imageDataNew = imageData.replace(fillRegex, replace);
|
18
|
+
|
19
|
+
// remove fillOpacity
|
20
|
+
const fillOpacityRegex = /fill-opacity="[^"]+"/g;
|
21
|
+
imageDataNew = imageDataNew.replace(fillOpacityRegex, '');
|
22
|
+
|
23
|
+
return imageDataNew;
|
24
|
+
}
|
25
|
+
|
26
|
+
export function getCssColorIcon(imageData: string, icon: IconRef): string {
|
27
|
+
// replace fill color with currentColor
|
28
|
+
const fillRegex = /fill="([^"]+)"/g;
|
29
|
+
|
30
|
+
const replace = (match: string, color: string) => {
|
31
|
+
const cssClass = icon.styles[color];
|
32
|
+
if (cssClass === undefined) {
|
33
|
+
if (color === 'black') return 'fill="currentColor"';
|
34
|
+
if (color === 'none') return 'fill="none"';
|
35
|
+
if (color === 'white') return 'fill="none"';
|
36
|
+
if (color === '#C90000')
|
37
|
+
return 'fill="var(--alarm-enabled-background-color)"';
|
38
|
+
console.warn(
|
39
|
+
'No css class for color',
|
40
|
+
color,
|
41
|
+
icon.name,
|
42
|
+
Object.keys(icon.styles)
|
43
|
+
);
|
44
|
+
return 'fill="currentColor"';
|
45
|
+
}
|
46
|
+
return `style="fill: var(--${cssClass.cssClass})"`;
|
47
|
+
};
|
48
|
+
imageData = imageData.replace(fillRegex, replace);
|
49
|
+
|
50
|
+
// remove fillOpacity
|
51
|
+
const fillOpacityRegex = /fill-opacity="[^"]+"/g;
|
52
|
+
imageData = imageData.replace(fillOpacityRegex, '');
|
53
|
+
|
54
|
+
// replace stroke color with currentColor
|
55
|
+
const strokeRegex = /stroke="([^"]+)"/g;
|
56
|
+
const replaceStroke = (match: string, color: string) => {
|
57
|
+
const cssClass = icon.styles[color];
|
58
|
+
if (cssClass === undefined) {
|
59
|
+
if (color === 'black') return 'stroke="currentColor"';
|
60
|
+
if (color === 'none') return 'stroke="none"';
|
61
|
+
if (color === 'white') return 'stroke="none"';
|
62
|
+
console.warn(
|
63
|
+
'No css class for color',
|
64
|
+
color,
|
65
|
+
icon.name,
|
66
|
+
Object.keys(icon.styles)
|
67
|
+
);
|
68
|
+
return 'stroke="currentColor"';
|
69
|
+
}
|
70
|
+
return `style="stroke: var(--${cssClass.cssClass})"`;
|
71
|
+
};
|
72
|
+
imageData = imageData.replace(strokeRegex, replaceStroke);
|
73
|
+
|
74
|
+
// remove strokeOpacity
|
75
|
+
const strokeOpacityRegex = /stroke-opacity="[^"]+"/g;
|
76
|
+
imageData = imageData.replace(strokeOpacityRegex, '');
|
77
|
+
|
78
|
+
return imageData;
|
79
|
+
}
|
80
|
+
|
81
|
+
export function kebabToUpperCamelCase(kebabCase: string): string {
|
82
|
+
const words = kebabCase.replace(/ /g, '').split('-');
|
83
|
+
const upperCamelCase = words
|
84
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
85
|
+
.join('');
|
86
|
+
return upperCamelCase;
|
87
|
+
}
|
88
|
+
|
89
|
+
export function getStylesForNode(
|
90
|
+
node: Figma.Node,
|
91
|
+
styles: {[styleId: string]: Figma.Style}
|
92
|
+
): {[colorCode: string]: {cssClass: string}} {
|
93
|
+
let out = {};
|
94
|
+
|
95
|
+
if ('children' in node) {
|
96
|
+
for (const child of node.children) {
|
97
|
+
out = {...out, ...getStylesForNode(child, styles)};
|
98
|
+
if ('fills' in child && 'styles' in child) {
|
99
|
+
let fils: string | undefined;
|
100
|
+
child.fills.forEach((fill) => {
|
101
|
+
if (fill.type === 'SOLID') {
|
102
|
+
if (fils !== undefined) {
|
103
|
+
console.warn(
|
104
|
+
'Multiple fills',
|
105
|
+
fils,
|
106
|
+
rgbaToHexOrColorName(fill.color!)
|
107
|
+
);
|
108
|
+
}
|
109
|
+
fils = rgbaToHexOrColorName(fill.color!);
|
110
|
+
}
|
111
|
+
});
|
112
|
+
if (fils !== undefined && child.styles && 'fill' in child.styles) {
|
113
|
+
const styleId = child.styles.fill as string;
|
114
|
+
const figmaStyle = styles[styleId];
|
115
|
+
const cssClass = styleToCssClass(figmaStyle);
|
116
|
+
out[fils] = {cssClass: cssClass};
|
117
|
+
}
|
118
|
+
}
|
119
|
+
if ('strokes' in child && 'styles' in child) {
|
120
|
+
let strokes: string;
|
121
|
+
child.strokes.forEach((fill) => {
|
122
|
+
if (fill.type === 'SOLID') {
|
123
|
+
if (strokes !== undefined) {
|
124
|
+
console.warn(
|
125
|
+
'Multiple strokes',
|
126
|
+
strokes,
|
127
|
+
rgbaToHexOrColorName(fill.color!)
|
128
|
+
);
|
129
|
+
}
|
130
|
+
strokes = rgbaToHexOrColorName(fill.color!);
|
131
|
+
}
|
132
|
+
});
|
133
|
+
if (strokes !== undefined && child.styles?.stroke) {
|
134
|
+
const styleId = child.styles.stroke;
|
135
|
+
const figmaStyle = styles[styleId];
|
136
|
+
const cssClass = styleToCssClass(figmaStyle);
|
137
|
+
out[strokes] = {cssClass: cssClass};
|
138
|
+
}
|
139
|
+
}
|
140
|
+
if ('fillOverrideTable' in child) {
|
141
|
+
for (const fill of Object.values(child.fillOverrideTable)) {
|
142
|
+
if (fill === null) continue;
|
143
|
+
if (!('inheritFillStyleId' in fill)) continue;
|
144
|
+
const styleId = fill.inheritFillStyleId;
|
145
|
+
const figmaStyle = styles[styleId];
|
146
|
+
const color = rgbaToHexOrColorName(fill.fills[0].color!);
|
147
|
+
const cssClass = styleToCssClass(figmaStyle);
|
148
|
+
out[color] = {cssClass: cssClass};
|
149
|
+
}
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}
|
153
|
+
return out;
|
154
|
+
}
|
155
|
+
|
156
|
+
function decimalToHex(d: number): string {
|
157
|
+
const v = Math.round(d * 255).toString(16);
|
158
|
+
return v.length === 1 ? `0${v}` : v;
|
159
|
+
}
|
160
|
+
|
161
|
+
function rgbaToHexOrColorName(rgba: Figma.Color): string {
|
162
|
+
const isBlack = rgba.r === 0 && rgba.g === 0 && rgba.b === 0 && rgba.a === 1;
|
163
|
+
const isWhite = rgba.r === 1 && rgba.g === 1 && rgba.b === 1 && rgba.a === 1;
|
164
|
+
if (isBlack) {
|
165
|
+
return 'black';
|
166
|
+
} else if (isWhite) {
|
167
|
+
return 'white';
|
168
|
+
} else {
|
169
|
+
return `#${decimalToHex(rgba.r)}${decimalToHex(rgba.g)}${decimalToHex(
|
170
|
+
rgba.b
|
171
|
+
)}`.toUpperCase();
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
function styleToCssClass(style: Figma.Style): string {
|
176
|
+
return style.name.replace(/[\/ ]/g, '-').toLocaleLowerCase();
|
177
|
+
}
|
@@ -0,0 +1,180 @@
|
|
1
|
+
import * as Figma from 'figma-api';
|
2
|
+
import * as dotenv from 'dotenv';
|
3
|
+
import * as fs from 'fs';
|
4
|
+
import {GetFileResult} from 'figma-api/lib/api-types';
|
5
|
+
import {
|
6
|
+
IconRef,
|
7
|
+
getCssColorIcon,
|
8
|
+
getStylesForNode,
|
9
|
+
kebabToUpperCamelCase,
|
10
|
+
} from './convert-icons';
|
11
|
+
|
12
|
+
dotenv.config();
|
13
|
+
|
14
|
+
const documentId = 'TPoHGyeEtlcpnNekOa4lY3';
|
15
|
+
|
16
|
+
const useCache = false;
|
17
|
+
|
18
|
+
const iconMapUrl: {url: string; name: string; typeA: boolean}[] = [
|
19
|
+
{
|
20
|
+
url: 'https://www.figma.com/file/TPoHGyeEtlcpnNekOa4lY3/OpenBridge-CAM?type=design&node-id=850-47442&mode=design&t=QA1ohadrbRZxW1ss-4',
|
21
|
+
name: '14-alarm-unack',
|
22
|
+
typeA: true,
|
23
|
+
},
|
24
|
+
{
|
25
|
+
url: 'https://www.figma.com/file/TPoHGyeEtlcpnNekOa4lY3/OpenBridge-CAM?type=design&node-id=850-47508&mode=design&t=QA1ohadrbRZxW1ss-4',
|
26
|
+
name: '14-alarm-unack',
|
27
|
+
typeA: false,
|
28
|
+
},
|
29
|
+
{
|
30
|
+
url: 'https://www.figma.com/file/TPoHGyeEtlcpnNekOa4lY3/OpenBridge-CAM?type=design&node-id=850-47481&mode=design&t=QA1ohadrbRZxW1ss-4',
|
31
|
+
name: '14-alarm-silenced',
|
32
|
+
typeA: true,
|
33
|
+
},
|
34
|
+
{
|
35
|
+
url: 'https://www.figma.com/file/TPoHGyeEtlcpnNekOa4lY3/OpenBridge-CAM?type=design&node-id=850-47505&mode=design&t=QA1ohadrbRZxW1ss-4',
|
36
|
+
name: '14-alarm-silenced',
|
37
|
+
typeA: false,
|
38
|
+
},
|
39
|
+
{
|
40
|
+
url: 'https://www.figma.com/file/TPoHGyeEtlcpnNekOa4lY3/OpenBridge-CAM?type=design&node-id=850-47445&mode=design&t=QA1ohadrbRZxW1ss-4',
|
41
|
+
name: '14-warning-unack',
|
42
|
+
typeA: true,
|
43
|
+
},
|
44
|
+
{
|
45
|
+
url: 'https://www.figma.com/file/TPoHGyeEtlcpnNekOa4lY3/OpenBridge-CAM?type=design&node-id=850-47475&mode=design&t=QA1ohadrbRZxW1ss-4',
|
46
|
+
name: '14-warning-unack',
|
47
|
+
typeA: false,
|
48
|
+
},
|
49
|
+
];
|
50
|
+
|
51
|
+
const iconMap: {id: string; name: string; typeA: boolean}[] = iconMapUrl.map(
|
52
|
+
(icon) => {
|
53
|
+
let id = icon.url.match(/node-id=([0-9/-]+)/)![1];
|
54
|
+
// replace - with :
|
55
|
+
id = id.replace(/-/g, ':');
|
56
|
+
return {id, name: icon.name, typeA: icon.typeA};
|
57
|
+
}
|
58
|
+
);
|
59
|
+
|
60
|
+
const iconDir = './src/components/alert-icon/icons';
|
61
|
+
|
62
|
+
export async function main() {
|
63
|
+
// delete all icons
|
64
|
+
|
65
|
+
if (fs.existsSync(iconDir)) {
|
66
|
+
const files = fs.readdirSync(iconDir);
|
67
|
+
for (const file of files) {
|
68
|
+
fs.unlinkSync(`${iconDir}/${file}`);
|
69
|
+
}
|
70
|
+
} else {
|
71
|
+
fs.mkdirSync(iconDir);
|
72
|
+
}
|
73
|
+
|
74
|
+
const api = new Figma.Api({
|
75
|
+
personalAccessToken: process.env.FIGMA_TOKEN as string,
|
76
|
+
});
|
77
|
+
|
78
|
+
const cachepath = './script/.cache-figma-alert.json';
|
79
|
+
let file: GetFileResult;
|
80
|
+
if (fs.existsSync(cachepath) && useCache) {
|
81
|
+
file = JSON.parse(fs.readFileSync(cachepath, 'utf8'));
|
82
|
+
} else {
|
83
|
+
file = await api.getFile(documentId, {ids: ['850:47441']});
|
84
|
+
// save to cache
|
85
|
+
fs.writeFileSync(cachepath, JSON.stringify(file, null, 2));
|
86
|
+
}
|
87
|
+
console.log('Got page');
|
88
|
+
const page = file.document.children.find(
|
89
|
+
(p) => p.name === 'Icons'
|
90
|
+
) as Figma.Node<'CANVAS'>;
|
91
|
+
const frames = page.children.filter(
|
92
|
+
(child) => child.name === 'Frame 3'
|
93
|
+
) as Figma.Node<'FRAME'>[];
|
94
|
+
const styles = file.styles;
|
95
|
+
|
96
|
+
const knownIds = iconMap.map((icon) => icon.id);
|
97
|
+
let icons = frames.flatMap((frame): IconRef[] => {
|
98
|
+
return frame.children
|
99
|
+
.filter((child) => knownIds.includes(child.id))
|
100
|
+
.map((child) => {
|
101
|
+
const icon = iconMap.find((icon) => icon.id === child.id);
|
102
|
+
const name = icon!.name + (icon!.typeA ? '-a' : '-b');
|
103
|
+
const javascriptName = 'svg' + kebabToUpperCamelCase(name);
|
104
|
+
return {
|
105
|
+
name: name,
|
106
|
+
id: child.id,
|
107
|
+
javascriptName: javascriptName,
|
108
|
+
styles: getStylesForNode(child, styles),
|
109
|
+
};
|
110
|
+
});
|
111
|
+
});
|
112
|
+
|
113
|
+
// remove duplicate icon names
|
114
|
+
const seen = new Set();
|
115
|
+
icons = icons.filter((icon) => {
|
116
|
+
const duplicate = seen.has(icon.javascriptName);
|
117
|
+
seen.add(icon.javascriptName);
|
118
|
+
if (duplicate) {
|
119
|
+
console.log('Duplicate icon name', icon.name);
|
120
|
+
}
|
121
|
+
return !duplicate;
|
122
|
+
});
|
123
|
+
|
124
|
+
// download all icons
|
125
|
+
if (!useCache) {
|
126
|
+
const split = 50;
|
127
|
+
for (let i = 0; i < icons.length; i += split) {
|
128
|
+
console.log('Got images', i);
|
129
|
+
const iconChunks = icons.slice(i, i + split);
|
130
|
+
const images = await api.getImage(documentId, {
|
131
|
+
ids: iconChunks.map((icon) => icon.id).join(','),
|
132
|
+
scale: 1,
|
133
|
+
format: 'svg',
|
134
|
+
});
|
135
|
+
|
136
|
+
// write icons to disk
|
137
|
+
await Promise.all(
|
138
|
+
Object.keys(images.images).map(async (nodeId) => {
|
139
|
+
const icon = icons.find((icon) => icon.id === nodeId);
|
140
|
+
const imageUrl = images.images[nodeId];
|
141
|
+
if (icon && imageUrl) {
|
142
|
+
// download icons
|
143
|
+
const request = await fetch(imageUrl);
|
144
|
+
const imageData = await request.text();
|
145
|
+
fs.writeFileSync(
|
146
|
+
`./script/.cache/alert-icons/${icon.name}.svg`,
|
147
|
+
imageData
|
148
|
+
);
|
149
|
+
}
|
150
|
+
})
|
151
|
+
);
|
152
|
+
}
|
153
|
+
}
|
154
|
+
|
155
|
+
const fileImport: string[] = [];
|
156
|
+
for (const icon of icons) {
|
157
|
+
const imageData = fs.readFileSync(
|
158
|
+
`./script/.cache/alert-icons/${icon.name}.svg`,
|
159
|
+
'utf8'
|
160
|
+
);
|
161
|
+
const cssColorIcon = getCssColorIcon(imageData, icon);
|
162
|
+
|
163
|
+
// convert icon.name from kebab case to upper cammel case
|
164
|
+
const name = icon.name.toLowerCase();
|
165
|
+
|
166
|
+
const component = `import {svg} from 'lit';
|
167
|
+
export const ${icon.javascriptName} = svg\`${cssColorIcon}\`;
|
168
|
+
`;
|
169
|
+
fs.writeFileSync(`${iconDir}/icon-${name}.ts`, component);
|
170
|
+
fileImport.push(
|
171
|
+
`import {${icon.javascriptName}} from './icons/icon-${name}';`
|
172
|
+
);
|
173
|
+
}
|
174
|
+
|
175
|
+
fileImport.sort();
|
176
|
+
console.log(fileImport.join('\n'));
|
177
|
+
console.log('done');
|
178
|
+
}
|
179
|
+
|
180
|
+
main();
|