@oicl/openbridge-webcomponents 0.0.8 → 0.0.10
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/.release-it.json +12 -0
- package/.storybook/main.ts +17 -0
- package/.storybook/preview.ts +0 -1
- package/CHANGELOG.md +118 -41
- package/__snapshots__/application-topbar--inactive.png +0 -0
- package/__snapshots__/button-button--raised-disabled.png +0 -0
- package/__snapshots__/button-rich-button--with-graphic-info.png +0 -0
- package/__snapshots__/input-slider--no-icons.png +0 -0
- package/__snapshots__/input-slider--no-value.png +0 -0
- package/__snapshots__/line-corner-line--primary.png +0 -0
- package/__snapshots__/line-example--air.png +0 -0
- package/__snapshots__/line-example--connector.png +0 -0
- package/__snapshots__/line-example--electric.png +0 -0
- package/__snapshots__/line-example--fluid.png +0 -0
- package/__snapshots__/line-horizontal-line--primary.png +0 -0
- package/__snapshots__/line-vertical-line--complex.png +0 -0
- package/__snapshots__/line-vertical-line--primary.png +0 -0
- package/custom-elements.json +679 -297
- package/dist/automation/corner-line/corner-line.d.ts +22 -0
- package/dist/automation/corner-line/corner-line.d.ts.map +1 -0
- package/dist/automation/corner-line/corner-line.js +161 -0
- package/dist/automation/corner-line/corner-line.js.map +1 -0
- package/dist/automation/horizontal-line/horizontal-line.d.ts +15 -0
- package/dist/automation/horizontal-line/horizontal-line.d.ts.map +1 -0
- package/dist/automation/horizontal-line/horizontal-line.js +110 -0
- package/dist/automation/horizontal-line/horizontal-line.js.map +1 -0
- package/dist/automation/index.d.ts +20 -0
- package/dist/automation/index.d.ts.map +1 -0
- package/dist/automation/index.js +42 -0
- package/dist/automation/index.js.map +1 -0
- package/dist/automation/vertical-line/vertical-line.d.ts +15 -0
- package/dist/automation/vertical-line/vertical-line.d.ts.map +1 -0
- package/dist/automation/vertical-line/vertical-line.js +111 -0
- package/dist/automation/vertical-line/vertical-line.js.map +1 -0
- package/dist/components/brilliance-menu/brilliance-menu.d.ts.map +1 -1
- package/dist/components/brilliance-menu/brilliance-menu.js +2 -0
- package/dist/components/brilliance-menu/brilliance-menu.js.map +1 -1
- package/dist/components/button/button.css.js +2 -2
- package/dist/components/navigation-item/navigation-item.css.js +2 -1
- package/dist/components/navigation-item/navigation-item.css.js.map +1 -1
- package/dist/components/notification-button/notification-button.css.js +1 -1
- package/dist/components/rich-button/rich-button.css.js +20 -10
- package/dist/components/rich-button/rich-button.css.js.map +1 -1
- package/dist/components/rich-button/rich-button.d.ts +1 -0
- package/dist/components/rich-button/rich-button.d.ts.map +1 -1
- package/dist/components/rich-button/rich-button.js +5 -0
- package/dist/components/rich-button/rich-button.js.map +1 -1
- package/dist/components/slider/slider.css.js +20 -0
- package/dist/components/slider/slider.css.js.map +1 -1
- package/dist/components/slider/slider.d.ts +8 -0
- package/dist/components/slider/slider.d.ts.map +1 -1
- package/dist/components/slider/slider.js +44 -18
- package/dist/components/slider/slider.js.map +1 -1
- package/dist/components/top-bar/top-bar.css.js +5 -1
- package/dist/components/top-bar/top-bar.css.js.map +1 -1
- package/dist/components/top-bar/top-bar.d.ts.map +1 -1
- package/dist/components/top-bar/top-bar.js +8 -8
- package/dist/components/top-bar/top-bar.js.map +1 -1
- package/fix-generated.cjs +1 -0
- package/package.json +20 -26
- package/src/automation/corner-line/corner-line.stories.ts +31 -0
- package/src/automation/corner-line/corner-line.ts +167 -0
- package/src/automation/horizontal-line/horizontal-line.stories.ts +28 -0
- package/src/automation/horizontal-line/horizontal-line.ts +100 -0
- package/src/automation/index.ts +41 -0
- package/src/automation/line.stories.ts +142 -0
- package/src/automation/vertical-line/vertical-line.stories.ts +71 -0
- package/src/automation/vertical-line/vertical-line.ts +104 -0
- package/src/components/brilliance-menu/brilliance-menu.ts +2 -0
- package/src/components/rich-button/rich-button.css +15 -2
- package/src/components/rich-button/rich-button.stories.ts +36 -0
- package/src/components/rich-button/rich-button.ts +2 -0
- package/src/components/slider/slider.css +20 -0
- package/src/components/slider/slider.stories.ts +20 -1
- package/src/components/slider/slider.ts +43 -19
- package/src/components/top-bar/top-bar.css +4 -0
- package/src/components/top-bar/top-bar.ts +10 -8
- package/src/palettes/variables.css +64 -43
- package/.yarnrc.yml +0 -1
- package/script/svg-instruments/convert-svg.ts +0 -246
- package/script/svg-instruments/environment.d.ts +0 -7
- package/script/svg-instruments/exports.ts +0 -82
- package/script/svg-instruments/figma-types.ts +0 -804
- package/script/svg-instruments/figmaImport.ts +0 -79
- package/script/svg-instruments/main.ts +0 -109
- package/test.svg +0 -3
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import {FrameNode, StyleDict, StyledNode} from './figma-types';
|
|
2
|
-
import {DOMParser, XMLSerializer} from 'xmldom';
|
|
3
|
-
|
|
4
|
-
function childNodes2Elements(nodes: NodeListOf<ChildNode>): Element[] {
|
|
5
|
-
const data = [];
|
|
6
|
-
for (let i = 0; i < nodes.length; i++) {
|
|
7
|
-
const node = nodes[i];
|
|
8
|
-
if (node.nodeName === '#text') continue;
|
|
9
|
-
if (node.nodeName === 'defs') continue;
|
|
10
|
-
data.push(node as Element);
|
|
11
|
-
}
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function getSvgId(svgNode: Element): string {
|
|
16
|
-
let svgId = (svgNode.getAttribute('id') as string).replace('°', '°');
|
|
17
|
-
const reDeg = /°/gi;
|
|
18
|
-
svgId = svgId.replace(reDeg, '°');
|
|
19
|
-
const re = new RegExp('_[0-9]+$');
|
|
20
|
-
if (svgId.match(re)) {
|
|
21
|
-
svgId = svgId.replace(re, '');
|
|
22
|
-
}
|
|
23
|
-
return svgId;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function replaceAll(string: string, search: string, replace: string): string {
|
|
27
|
-
return string.split(search).join(replace);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function makeid(): string {
|
|
31
|
-
let result = '';
|
|
32
|
-
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
33
|
-
const charactersLength = characters.length;
|
|
34
|
-
for (let i = 0; i < 10; i++) {
|
|
35
|
-
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
36
|
-
}
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function convertSvg(
|
|
41
|
-
figmaElement: FrameNode,
|
|
42
|
-
svgString: string,
|
|
43
|
-
styles: StyleDict,
|
|
44
|
-
removeAttrs: boolean
|
|
45
|
-
): string {
|
|
46
|
-
const svgDoc = new DOMParser().parseFromString(svgString, 'text/svg');
|
|
47
|
-
const root = svgDoc.firstChild;
|
|
48
|
-
if (root === null) return '';
|
|
49
|
-
|
|
50
|
-
for (const nd of childNodes2Elements(root.childNodes)) {
|
|
51
|
-
const svgId = getSvgId(nd);
|
|
52
|
-
const elementId = figmaElement.name;
|
|
53
|
-
if (svgId !== elementId) {
|
|
54
|
-
console.warn(
|
|
55
|
-
`Figma element id and svg id does not match (${elementId} !== ${svgId})`
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
parseNode(figmaElement as unknown as StyledNode, nd, styles, removeAttrs);
|
|
59
|
-
}
|
|
60
|
-
let out = new XMLSerializer().serializeToString(svgDoc);
|
|
61
|
-
const clipPrefix = makeid();
|
|
62
|
-
out = replaceAll(out, 'url(#clip', `url(#${clipPrefix}clip`);
|
|
63
|
-
out = replaceAll(out, 'clipPath id="clip', `clipPath id="${clipPrefix}clip`);
|
|
64
|
-
out = replaceAll(out, 'url(#path-', `url(#${clipPrefix}path-`);
|
|
65
|
-
out = replaceAll(out, 'mask id="path-', `mask id="${clipPrefix}path-`);
|
|
66
|
-
return out;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function findFigmaNode(
|
|
70
|
-
figmaElement: StyledNode,
|
|
71
|
-
svgNode: Element
|
|
72
|
-
): StyledNode | undefined {
|
|
73
|
-
const path = getSvgPath(svgNode);
|
|
74
|
-
path.shift();
|
|
75
|
-
return searchFigmaNode(figmaElement, path);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** Searching for figma node matching the svg id path.
|
|
79
|
-
*
|
|
80
|
-
* Supports figma nodes having same name.
|
|
81
|
-
* @param figmaElement
|
|
82
|
-
* @param svgIds
|
|
83
|
-
*/
|
|
84
|
-
function searchFigmaNode(
|
|
85
|
-
figmaElement: StyledNode,
|
|
86
|
-
svgIds: string[]
|
|
87
|
-
): StyledNode | undefined {
|
|
88
|
-
if (svgIds.length === 0) return figmaElement;
|
|
89
|
-
if (figmaElement.children === undefined) return undefined;
|
|
90
|
-
|
|
91
|
-
const currentId = svgIds.shift();
|
|
92
|
-
const figmaNodes = figmaElement.children
|
|
93
|
-
.filter((f) => f.name === currentId && f.visible !== false)
|
|
94
|
-
.map((f) => {
|
|
95
|
-
const ids = [...svgIds];
|
|
96
|
-
return searchFigmaNode(f, ids);
|
|
97
|
-
})
|
|
98
|
-
.filter((value) => value !== undefined) as StyledNode[];
|
|
99
|
-
if (figmaNodes.length > 0) return figmaNodes[0];
|
|
100
|
-
else return undefined;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function getSvgPath(svgNode: Element): string[] {
|
|
104
|
-
if (svgNode.parentNode === null) return [];
|
|
105
|
-
const svgId = getSvgId(svgNode);
|
|
106
|
-
|
|
107
|
-
const ids = getSvgPath(svgNode.parentNode as Element);
|
|
108
|
-
if (svgId.length !== 0) {
|
|
109
|
-
ids.push(svgId);
|
|
110
|
-
}
|
|
111
|
-
return ids;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function parseNode(
|
|
115
|
-
figmaRoot: StyledNode,
|
|
116
|
-
svgNode: Element,
|
|
117
|
-
styles: StyleDict,
|
|
118
|
-
removeAttrs: boolean
|
|
119
|
-
) {
|
|
120
|
-
const figmaNode = findFigmaNode(figmaRoot, svgNode);
|
|
121
|
-
if (figmaNode === undefined) {
|
|
122
|
-
console.warn(
|
|
123
|
-
`Missing figma node: ${svgNode.getAttribute('id')}. Skipping subnodes.`
|
|
124
|
-
);
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const cssClasses = [];
|
|
129
|
-
if (svgNode.hasAttribute('id')) {
|
|
130
|
-
if (
|
|
131
|
-
svgNode.hasAttribute('id') &&
|
|
132
|
-
figmaNode.styles &&
|
|
133
|
-
figmaNode.styles.stroke &&
|
|
134
|
-
svgNode.hasAttribute('stroke')
|
|
135
|
-
) {
|
|
136
|
-
if (removeAttrs) {
|
|
137
|
-
svgNode.removeAttribute('stroke');
|
|
138
|
-
svgNode.removeAttribute('stroke-opacity');
|
|
139
|
-
}
|
|
140
|
-
const strokeStyleId = figmaNode.styles.stroke;
|
|
141
|
-
if (strokeStyleId !== undefined) {
|
|
142
|
-
const styleName = convertStyleName(
|
|
143
|
-
styles[strokeStyleId].name,
|
|
144
|
-
'-stroke'
|
|
145
|
-
);
|
|
146
|
-
cssClasses.push(styleName);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (
|
|
151
|
-
svgNode.hasAttribute('id') &&
|
|
152
|
-
figmaNode.styles &&
|
|
153
|
-
figmaNode.styles.fill &&
|
|
154
|
-
svgNode.hasAttribute('fill')
|
|
155
|
-
) {
|
|
156
|
-
if (removeAttrs) {
|
|
157
|
-
svgNode.removeAttribute('fill');
|
|
158
|
-
}
|
|
159
|
-
const strokeStyleId = figmaNode.styles.fill;
|
|
160
|
-
if (strokeStyleId !== undefined) {
|
|
161
|
-
const styleName = convertStyleName(styles[strokeStyleId].name, '-fill');
|
|
162
|
-
cssClasses.push(styleName);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
} else if (figmaNode.styles) {
|
|
166
|
-
const hasBackground =
|
|
167
|
-
figmaNode.background && figmaNode.background.length === 1;
|
|
168
|
-
const svgHasFill = svgNode.hasAttribute('fill');
|
|
169
|
-
const hasStrokeInsideOrOutside =
|
|
170
|
-
figmaNode.strokeAlign &&
|
|
171
|
-
(figmaNode.strokeAlign === 'INSIDE' ||
|
|
172
|
-
figmaNode.strokeAlign === 'OUTSIDE');
|
|
173
|
-
const mask = svgNode.getAttribute('mask');
|
|
174
|
-
const hasMaskInsideOrOutside =
|
|
175
|
-
mask && (mask.match(/inside/) || mask.match(/outside/));
|
|
176
|
-
if (
|
|
177
|
-
svgHasFill &&
|
|
178
|
-
!hasMaskInsideOrOutside &&
|
|
179
|
-
((hasBackground && figmaNode.styles.fills) || figmaNode.styles.fill)
|
|
180
|
-
) {
|
|
181
|
-
// Special case for background fill for frame
|
|
182
|
-
if (removeAttrs) {
|
|
183
|
-
svgNode.removeAttribute('fill');
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const strokeStyleId = figmaNode.styles.fills || figmaNode.styles.fill;
|
|
187
|
-
if (strokeStyleId !== undefined) {
|
|
188
|
-
const styleName = convertStyleName(styles[strokeStyleId].name, '-fill');
|
|
189
|
-
cssClasses.push(styleName);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (
|
|
194
|
-
hasStrokeInsideOrOutside &&
|
|
195
|
-
hasMaskInsideOrOutside &&
|
|
196
|
-
svgHasFill &&
|
|
197
|
-
figmaNode.styles &&
|
|
198
|
-
figmaNode.styles.stroke
|
|
199
|
-
) {
|
|
200
|
-
if (removeAttrs) {
|
|
201
|
-
svgNode.removeAttribute('fill');
|
|
202
|
-
}
|
|
203
|
-
const strokeStyleId = figmaNode.styles.stroke;
|
|
204
|
-
if (strokeStyleId !== undefined) {
|
|
205
|
-
const styleName = convertStyleName(styles[strokeStyleId].name, '-fill');
|
|
206
|
-
cssClasses.push(styleName);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const hasStroke = figmaNode.strokes && figmaNode.strokes.length === 1;
|
|
211
|
-
if (
|
|
212
|
-
hasStroke &&
|
|
213
|
-
svgNode.hasAttribute('stroke') &&
|
|
214
|
-
figmaNode.styles &&
|
|
215
|
-
figmaNode.styles.strokes
|
|
216
|
-
) {
|
|
217
|
-
// Special case for stroke on frame
|
|
218
|
-
if (removeAttrs) {
|
|
219
|
-
svgNode.removeAttribute('stroke');
|
|
220
|
-
}
|
|
221
|
-
const strokeStyleId = figmaNode.styles.strokes;
|
|
222
|
-
if (strokeStyleId !== undefined) {
|
|
223
|
-
const styleName = convertStyleName(
|
|
224
|
-
styles[strokeStyleId].name,
|
|
225
|
-
'-stroke'
|
|
226
|
-
);
|
|
227
|
-
cssClasses.push(styleName);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (cssClasses.length > 0) {
|
|
233
|
-
svgNode.setAttribute('class', cssClasses.join(' '));
|
|
234
|
-
}
|
|
235
|
-
const childSvgs = childNodes2Elements(svgNode.childNodes);
|
|
236
|
-
if (childSvgs.length > 0) {
|
|
237
|
-
for (let i = 0; i < childSvgs.length; i++) {
|
|
238
|
-
const svgNode = childSvgs[i];
|
|
239
|
-
parseNode(figmaRoot, svgNode, styles, removeAttrs);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function convertStyleName(str: string, suffix: string): string {
|
|
245
|
-
return 'ob-' + str.replace(/\//g, '-').toLowerCase() + suffix;
|
|
246
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
export interface ExportDef {
|
|
2
|
-
name: string;
|
|
3
|
-
path: string[]; // Array of subpath for targeting the svg export in Figma
|
|
4
|
-
outputFolder: string; // sub folder of ./gen
|
|
5
|
-
nonScaling?: boolean;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const staticExportComponents: ExportDef[] = [];
|
|
9
|
-
|
|
10
|
-
function tickMarks(): ExportDef[] {
|
|
11
|
-
const circleDegrees = ['0', '1', '2', '5', '9', '10', '30', '45', '90'];
|
|
12
|
-
const tickType = ['Primary', 'Secondary', 'Tertiary'];
|
|
13
|
-
const circleTickMarks: ExportDef[] = [];
|
|
14
|
-
|
|
15
|
-
for (const degree of circleDegrees) {
|
|
16
|
-
for (const tick of tickType) {
|
|
17
|
-
const def: ExportDef = {
|
|
18
|
-
name: `${tick}Tickmark${degree}`,
|
|
19
|
-
path: [
|
|
20
|
-
'P2 Building blocks',
|
|
21
|
-
'Watchface elements',
|
|
22
|
-
'Tickmarks - Compass',
|
|
23
|
-
`Degree=${degree}°, Tick size=${tick}`,
|
|
24
|
-
],
|
|
25
|
-
outputFolder: 'Tickmarks',
|
|
26
|
-
nonScaling: true,
|
|
27
|
-
};
|
|
28
|
-
circleTickMarks.push(def);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const size = ['Medium', 'Large'];
|
|
33
|
-
const toplines: ExportDef[] = size.map((s) => ({
|
|
34
|
-
name: `Topline${s}`,
|
|
35
|
-
path: [
|
|
36
|
-
'P2 Building blocks',
|
|
37
|
-
'Watchface',
|
|
38
|
-
'Azimuth watchface',
|
|
39
|
-
`Size=${s}, Tickmarks=90°, Labels=False, Detailed=False, PORT / STBD=False`,
|
|
40
|
-
'watchface',
|
|
41
|
-
'top-line',
|
|
42
|
-
],
|
|
43
|
-
outputFolder: 'Tickmarks',
|
|
44
|
-
}));
|
|
45
|
-
return [...circleTickMarks, ...toplines];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function watchface(): ExportDef[] {
|
|
49
|
-
const watchface: ExportDef[] = [];
|
|
50
|
-
const types = [
|
|
51
|
-
{name: 'Regular', tag: 'Regular'},
|
|
52
|
-
{name: 'PORT STBD', tag: 'PORT_STBD'},
|
|
53
|
-
{name: 'Positive / Negative', tag: 'Positive_Negative'},
|
|
54
|
-
{name: 'Off', tag: 'Off'},
|
|
55
|
-
{name: 'Bar', tag: 'Bar'},
|
|
56
|
-
];
|
|
57
|
-
const size = ['Small', 'Medium', 'Large'];
|
|
58
|
-
|
|
59
|
-
for (const type of types) {
|
|
60
|
-
for (const s of size) {
|
|
61
|
-
const def: ExportDef = {
|
|
62
|
-
name: `${type.tag}Watchface${s}`,
|
|
63
|
-
path: [
|
|
64
|
-
'P2 Building blocks',
|
|
65
|
-
'Watchface elements',
|
|
66
|
-
'Watchface circle',
|
|
67
|
-
`Size=${s}, Type=${type.name}, Condensed=False, Arc=Off`,
|
|
68
|
-
],
|
|
69
|
-
outputFolder: 'Watchface',
|
|
70
|
-
};
|
|
71
|
-
watchface.push(def);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return watchface;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export const exportComponents = [
|
|
79
|
-
...staticExportComponents,
|
|
80
|
-
...tickMarks(),
|
|
81
|
-
...watchface(),
|
|
82
|
-
];
|