@ship-ui/core 0.13.2
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/LICENSE +21 -0
- package/README.md +3 -0
- package/assets/fonts/InterTight-VariableFont_wght.woff2 +0 -0
- package/bin/ship-fg-node +40 -0
- package/bin/ship-fg.ts +40 -0
- package/bin/src/ship-fg-node.js +344 -0
- package/bin/src/ship-fg.ts +368 -0
- package/bin/src/utilities.js +53 -0
- package/bin/src/utilities.ts +98 -0
- package/bin/tsconfig.app.json +15 -0
- package/fesm2022/ship-ui-core.mjs +5373 -0
- package/fesm2022/ship-ui-core.mjs.map +1 -0
- package/index.d.ts +758 -0
- package/package.json +52 -0
- package/styles/components/ship-alert-container.component.scss +49 -0
- package/styles/components/ship-alert.component.scss +273 -0
- package/styles/components/ship-button-group.component.scss +63 -0
- package/styles/components/ship-button.component.scss +330 -0
- package/styles/components/ship-card.component.scss +54 -0
- package/styles/components/ship-checkbox.component.scss +245 -0
- package/styles/components/ship-chip.component.scss +290 -0
- package/styles/components/ship-color-picker.component.scss +78 -0
- package/styles/components/ship-datepicker.component.scss +274 -0
- package/styles/components/ship-dialog.component.scss +119 -0
- package/styles/components/ship-divider.component.scss +27 -0
- package/styles/components/ship-file-upload.component.scss +47 -0
- package/styles/components/ship-form-field.component.scss +334 -0
- package/styles/components/ship-icon.component.scss +54 -0
- package/styles/components/ship-list.component.scss +148 -0
- package/styles/components/ship-menu.component.scss +217 -0
- package/styles/components/ship-popover.component.scss +66 -0
- package/styles/components/ship-progress-bar.component.scss +173 -0
- package/styles/components/ship-radio.component.scss +182 -0
- package/styles/components/ship-range-slider.component.scss +412 -0
- package/styles/components/ship-select.component.scss +139 -0
- package/styles/components/ship-sidenav.component.scss +192 -0
- package/styles/components/ship-sortable.component.scss +54 -0
- package/styles/components/ship-spinner.component.scss +53 -0
- package/styles/components/ship-stepper.component.scss +138 -0
- package/styles/components/ship-table.component.scss +402 -0
- package/styles/components/ship-tabs.component.scss +86 -0
- package/styles/components/ship-toggle-card.component.scss +71 -0
- package/styles/components/ship-toggle.component.scss +238 -0
- package/styles/components/ship-tooltip.component.scss +175 -0
- package/styles/components/ship-virtual-scroll.component.scss +12 -0
- package/styles/components/sparkle-checkbox.component.scss +245 -0
- package/styles/components/sparkle-select.component.scss +139 -0
- package/styles/core/apexcharts/apexcharts.scss +58 -0
- package/styles/core/core/layout.scss +74 -0
- package/styles/core/core/loader.scss +63 -0
- package/styles/core/core/palette-variables.scss +352 -0
- package/styles/core/core/typography.scss +103 -0
- package/styles/core/core/variables.scss +188 -0
- package/styles/core/core.scss +4 -0
- package/styles/core/fonts/_inter-tight.scss +11 -0
- package/styles/core/helpers/fn/color-mix.scss +7 -0
- package/styles/core/helpers/fn/dp.scss +14 -0
- package/styles/core/helpers/fn/p2r.scss +23 -0
- package/styles/core/helpers/mixins/border-gradient.scss +61 -0
- package/styles/core/helpers/mixins/breakpoint.scss +217 -0
- package/styles/core/helpers/mixins/ellipsis.scss +7 -0
- package/styles/core/helpers/mixins/overflow-scrolling.scss +18 -0
- package/styles/core/helpers/mixins/wrapper.scss +16 -0
- package/styles/core/polyfill/light-dark.scss +3 -0
- package/styles/helpers.scss +13 -0
- package/styles/index.scss +146 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import { Glob } from 'bun';
|
|
4
|
+
import { FSWatcher, watch } from 'fs';
|
|
5
|
+
import path, { join, resolve } from 'path';
|
|
6
|
+
|
|
7
|
+
import subsetFont from 'subset-font';
|
|
8
|
+
|
|
9
|
+
import { formatFileSize, getUnicodeObject, InputArguments, SupportedFontTypes } from './utilities';
|
|
10
|
+
|
|
11
|
+
let writtenCssSize = 0;
|
|
12
|
+
let compressedCssSize = 0;
|
|
13
|
+
|
|
14
|
+
const run = async (
|
|
15
|
+
PROJECT_SRC: string,
|
|
16
|
+
LIB_ICONS: string[],
|
|
17
|
+
PROJECT_PUBLIC: string,
|
|
18
|
+
GLYPH_MAP: Record<string, [string, string]>,
|
|
19
|
+
TARGET_FONT_TYPE: SupportedFontTypes,
|
|
20
|
+
values: InputArguments
|
|
21
|
+
) => {
|
|
22
|
+
const startTime = performance.now();
|
|
23
|
+
|
|
24
|
+
const glob = new Glob('**/*.html');
|
|
25
|
+
const tsGlob = new Glob('**/*.ts');
|
|
26
|
+
const regex = /<sh-icon[^>]*>\s*((?!{{.*?}})[^<]*?)\s*<\/sh-icon>/g;
|
|
27
|
+
const regex2 = /sh:([^']+)/g;
|
|
28
|
+
const iconsFound = new Set<string>(LIB_ICONS);
|
|
29
|
+
const missingIcons = new Set<string>();
|
|
30
|
+
|
|
31
|
+
for await (const file of glob.scan(`${PROJECT_SRC}`)) {
|
|
32
|
+
const fileText = await Bun.file(`${PROJECT_SRC}/${file}`).text();
|
|
33
|
+
const matches = Array.from((fileText as any).matchAll(regex), (m: string) => m[1]);
|
|
34
|
+
|
|
35
|
+
if (matches?.length) {
|
|
36
|
+
for (let index = 0; index < matches.length; index++) {
|
|
37
|
+
const match = matches[index];
|
|
38
|
+
|
|
39
|
+
if (match) iconsFound.add(match);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
for await (const file of tsGlob.scan(`${PROJECT_SRC}`)) {
|
|
45
|
+
const fileText = await Bun.file(`${PROJECT_SRC}/${file}`).text();
|
|
46
|
+
const matches = Array.from((fileText as any).matchAll(regex2), (m: string) => m[1]);
|
|
47
|
+
|
|
48
|
+
if (matches?.length) {
|
|
49
|
+
for (let index = 0; index < matches.length; index++) {
|
|
50
|
+
const match = matches[index];
|
|
51
|
+
|
|
52
|
+
if (match) iconsFound.add(match);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const groupedIcons = Array.from(iconsFound).reduce(
|
|
58
|
+
(acc, icon) => {
|
|
59
|
+
const bold = icon.endsWith('-bold');
|
|
60
|
+
const thin = icon.endsWith('-thin');
|
|
61
|
+
const light = icon.endsWith('-light');
|
|
62
|
+
const fill = icon.endsWith('-fill');
|
|
63
|
+
const regular = !bold && !thin && !light && !fill;
|
|
64
|
+
const glyph = GLYPH_MAP[icon];
|
|
65
|
+
|
|
66
|
+
if (!glyph) {
|
|
67
|
+
missingIcons.add(icon);
|
|
68
|
+
return acc;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (bold) {
|
|
72
|
+
acc['bold'].push([icon, '']);
|
|
73
|
+
acc['bold'].push(glyph);
|
|
74
|
+
}
|
|
75
|
+
if (thin) {
|
|
76
|
+
acc['thin'].push([icon, '']);
|
|
77
|
+
acc['thin'].push(glyph);
|
|
78
|
+
}
|
|
79
|
+
if (light) {
|
|
80
|
+
acc['light'].push([icon, '']);
|
|
81
|
+
acc['light'].push(glyph);
|
|
82
|
+
}
|
|
83
|
+
if (fill) {
|
|
84
|
+
acc['fill'].push([icon, '']);
|
|
85
|
+
acc['fill'].push(glyph);
|
|
86
|
+
}
|
|
87
|
+
if (regular) {
|
|
88
|
+
acc['regular'].push([icon, '']);
|
|
89
|
+
acc['regular'].push(glyph);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return acc;
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
bold: [],
|
|
96
|
+
thin: [],
|
|
97
|
+
light: [],
|
|
98
|
+
fill: [],
|
|
99
|
+
regular: [],
|
|
100
|
+
text: [],
|
|
101
|
+
} as {
|
|
102
|
+
[key: string]: [string, string][];
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const missingIconsArray = Array.from(missingIcons);
|
|
107
|
+
|
|
108
|
+
if (missingIconsArray.length) {
|
|
109
|
+
console.log('Following icons does not exist in font: \n ', Array.from(missingIcons));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
writeCssFile(PROJECT_PUBLIC, values, groupedIcons, TARGET_FONT_TYPE);
|
|
113
|
+
|
|
114
|
+
// We dont load fonts we dont use
|
|
115
|
+
const fontTypes = ['bold', 'thin', 'light', 'fill', 'regular'].filter((x) => groupedIcons[x].length > 0);
|
|
116
|
+
const targetFormat = (TARGET_FONT_TYPE as SupportedFontTypes) === 'ttf' ? 'truetype' : TARGET_FONT_TYPE;
|
|
117
|
+
const fonts = fontTypes.map(async (fontType) => {
|
|
118
|
+
const glyphs = uniqueString(groupedIcons[fontType].map((icon) => icon[0]).join(''));
|
|
119
|
+
const fontFileName = `Phosphor${fontType === 'regular' ? '' : '-' + capitalize(fontType)}.${TARGET_FONT_TYPE}`;
|
|
120
|
+
const fullPath = path.resolve(
|
|
121
|
+
process.cwd(),
|
|
122
|
+
'node_modules',
|
|
123
|
+
'@phosphor-icons',
|
|
124
|
+
'web',
|
|
125
|
+
'src',
|
|
126
|
+
fontType,
|
|
127
|
+
fontFileName
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const arrayBuffer = await Bun.file(fullPath).arrayBuffer();
|
|
131
|
+
const subsetBuffer = await subsetFont(Buffer.from(arrayBuffer), glyphs, {
|
|
132
|
+
targetFormat,
|
|
133
|
+
noLayoutClosure: true,
|
|
134
|
+
} as any);
|
|
135
|
+
|
|
136
|
+
return subsetBuffer;
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const _fonts = await Promise.all(fonts);
|
|
140
|
+
let totalFontSize = 0;
|
|
141
|
+
let totalCompressedFontSize = 0;
|
|
142
|
+
|
|
143
|
+
for (let i = 0; i < _fonts.length; i++) {
|
|
144
|
+
const subsetBuffer = _fonts[i];
|
|
145
|
+
const fontType = fontTypes[i];
|
|
146
|
+
const fontWrites = await Bun.write(
|
|
147
|
+
`${PROJECT_PUBLIC}/sh${fontType === 'regular' ? '' : '-' + fontType}.${TARGET_FONT_TYPE}`,
|
|
148
|
+
subsetBuffer
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const compressedFont = Bun.gzipSync(subsetBuffer);
|
|
152
|
+
const iconsOnGroup = groupedIcons[fontType].filter((icon) => icon[1] === '').map((icon) => icon[0]);
|
|
153
|
+
|
|
154
|
+
totalFontSize += fontWrites;
|
|
155
|
+
totalCompressedFontSize += compressedFont.length;
|
|
156
|
+
|
|
157
|
+
if (values.verbose) {
|
|
158
|
+
console.log('Group: ', fontType, '\n', iconsOnGroup);
|
|
159
|
+
console.log(
|
|
160
|
+
`Font & CSS (Generated/Compressed size): ${formatFileSize(fontWrites)}/${formatFileSize(compressedFont.length)}`
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
console.log(' ');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const endTime = performance.now();
|
|
168
|
+
const runtime = endTime - startTime;
|
|
169
|
+
console.log(
|
|
170
|
+
`Font & CSS (Generated/Compressed size): ${formatFileSize(totalFontSize + writtenCssSize)}/${formatFileSize(totalCompressedFontSize + compressedCssSize)}`
|
|
171
|
+
);
|
|
172
|
+
console.log('Time taken: ', runtime.toFixed(2) + 'ms');
|
|
173
|
+
console.log(' ');
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
function uniqueString(s: string): string {
|
|
177
|
+
const seen = new Set<string>(); // Use a Set to track seen characters
|
|
178
|
+
let result = '';
|
|
179
|
+
|
|
180
|
+
for (const char of s) {
|
|
181
|
+
if (!seen.has(char)) {
|
|
182
|
+
// Check if the character has been seen
|
|
183
|
+
seen.add(char); // Add the character to the seen set
|
|
184
|
+
result += char; // Append the character to the result
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const writeCssFile = async (
|
|
192
|
+
PROJECT_PUBLIC: string,
|
|
193
|
+
values: InputArguments,
|
|
194
|
+
groupedIcons: { [key: string]: [string, string][] },
|
|
195
|
+
TARGET_FONT_TYPE = 'woff2'
|
|
196
|
+
) => {
|
|
197
|
+
const groupedIconsEntries = Object.entries(groupedIcons).map(([key, value], i) => {
|
|
198
|
+
if (key === 'text') return '';
|
|
199
|
+
|
|
200
|
+
const suffix = key === 'regular' ? '' : '-' + key;
|
|
201
|
+
const fontUrl = `url('${values.rootPath}sh${suffix}.${TARGET_FONT_TYPE}') format('${TARGET_FONT_TYPE === 'ttf' ? 'truetype' : TARGET_FONT_TYPE}')`;
|
|
202
|
+
|
|
203
|
+
return `
|
|
204
|
+
@font-face {
|
|
205
|
+
font-family: 'sh${suffix}';
|
|
206
|
+
src: ${fontUrl};
|
|
207
|
+
font-weight: normal;
|
|
208
|
+
font-style: normal;
|
|
209
|
+
font-display: block;
|
|
210
|
+
}`;
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const keys = Object.keys(groupedIcons).map((key) => {
|
|
214
|
+
if (['regular', 'text'].includes(key)) return '';
|
|
215
|
+
|
|
216
|
+
const suffix = key === 'regular' ? '' : '-' + key;
|
|
217
|
+
|
|
218
|
+
return `
|
|
219
|
+
sh-icon.${key} {
|
|
220
|
+
font-family: 'sh${suffix}' !important;
|
|
221
|
+
}`;
|
|
222
|
+
});
|
|
223
|
+
// Create a new css file
|
|
224
|
+
const cssFileContent = `
|
|
225
|
+
${groupedIconsEntries.join('\n')}
|
|
226
|
+
${keys.join('\n')}
|
|
227
|
+
sh-icon {
|
|
228
|
+
/* use !important to prevent issues with browser extensions that change fonts */
|
|
229
|
+
font-family: "sh" !important;
|
|
230
|
+
speak: never;
|
|
231
|
+
font-style: normal;
|
|
232
|
+
font-weight: normal;
|
|
233
|
+
font-variant: normal;
|
|
234
|
+
text-transform: none;
|
|
235
|
+
line-height: 1;
|
|
236
|
+
|
|
237
|
+
/* Enable Ligatures ================ */
|
|
238
|
+
letter-spacing: 0;
|
|
239
|
+
-webkit-font-feature-settings: "liga";
|
|
240
|
+
-moz-font-feature-settings: "liga=1";
|
|
241
|
+
-moz-font-feature-settings: "liga";
|
|
242
|
+
-ms-font-feature-settings: "liga" 1;
|
|
243
|
+
font-feature-settings: "liga";
|
|
244
|
+
-webkit-font-variant-ligatures: discretionary-ligatures;
|
|
245
|
+
font-variant-ligatures: discretionary-ligatures;
|
|
246
|
+
|
|
247
|
+
/* Better Font Rendering =========== */
|
|
248
|
+
-webkit-font-smoothing: antialiased;
|
|
249
|
+
-moz-osx-font-smoothing: grayscale;
|
|
250
|
+
}`;
|
|
251
|
+
const cssWrites = await Bun.write(`${PROJECT_PUBLIC}/ship.css`, cssFileContent);
|
|
252
|
+
const compressedCss = Bun.gzipSync(cssFileContent);
|
|
253
|
+
|
|
254
|
+
writtenCssSize = cssWrites;
|
|
255
|
+
compressedCssSize = compressedCss.length;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const textMateSnippet = async (GLYPH_MAP: Record<string, [string, string]>) => {
|
|
259
|
+
const iconsSnippetContent = `
|
|
260
|
+
{
|
|
261
|
+
"Phosphor icons": {
|
|
262
|
+
"prefix": ["pp:icon"],
|
|
263
|
+
"scope": "javascript,typescript,html",
|
|
264
|
+
"body": "\${1|${Object.keys(GLYPH_MAP).join(',')}|}",
|
|
265
|
+
"description": "Add a phosphor icon"
|
|
266
|
+
},
|
|
267
|
+
"Ship sh-icon": {
|
|
268
|
+
"prefix": ["sh-icon"],
|
|
269
|
+
"scope": "html",
|
|
270
|
+
"body": "<sh-icon>\${1|${Object.keys(GLYPH_MAP).join(',')}|}</sh-icon>",
|
|
271
|
+
"description": "Add a ship phosphor icon"
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
`;
|
|
275
|
+
|
|
276
|
+
await Bun.write('./.vscode/html.code-snippets', iconsSnippetContent);
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
function capitalize(str: string) {
|
|
280
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export const main = async (values: InputArguments) => {
|
|
284
|
+
const TARGET_FONT_TYPE: SupportedFontTypes = 'woff2' as SupportedFontTypes;
|
|
285
|
+
const packageJsonPath = resolve(import.meta.dir, '../../package.json');
|
|
286
|
+
const packageJson = await Bun.file(packageJsonPath).json();
|
|
287
|
+
const PROJECT_SRC = values.src;
|
|
288
|
+
const PROJECT_PUBLIC = values.out;
|
|
289
|
+
const fontVariants = ['bold', 'thin', 'light', 'fill', 'regular'];
|
|
290
|
+
const GLYPH_MAPS = await Promise.all(
|
|
291
|
+
fontVariants.map(async (fontVariant) => {
|
|
292
|
+
const selectionJsonFullPath = path.resolve(
|
|
293
|
+
process.cwd(),
|
|
294
|
+
'node_modules',
|
|
295
|
+
'@phosphor-icons',
|
|
296
|
+
'web',
|
|
297
|
+
'src',
|
|
298
|
+
fontVariant,
|
|
299
|
+
'selection.json'
|
|
300
|
+
);
|
|
301
|
+
const selectionJson = await Bun.file(selectionJsonFullPath).json();
|
|
302
|
+
|
|
303
|
+
// return createCodepointObject(selectionJson.icons);
|
|
304
|
+
// return createNameCodeObject(selectionJson.icons);
|
|
305
|
+
return getUnicodeObject(selectionJson.icons);
|
|
306
|
+
})
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
const GLYPH_MAP = GLYPH_MAPS.reduce(
|
|
310
|
+
(acc, curr) => {
|
|
311
|
+
return {
|
|
312
|
+
...acc,
|
|
313
|
+
...curr,
|
|
314
|
+
};
|
|
315
|
+
},
|
|
316
|
+
{} as Record<string, [string, string]>
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
const LIB_ICONS = packageJson.libraryIcons as string[];
|
|
320
|
+
let watchers: FSWatcher[] = [];
|
|
321
|
+
|
|
322
|
+
textMateSnippet(GLYPH_MAP);
|
|
323
|
+
|
|
324
|
+
if (values.watch) {
|
|
325
|
+
const excludeFolders = ['node_modules', '.git', '.vscode', 'bin', 'assets'].concat([PROJECT_PUBLIC]);
|
|
326
|
+
const watcher = watch(PROJECT_SRC, { recursive: true }, (_, filename) => {
|
|
327
|
+
if (
|
|
328
|
+
filename && // Ensure filename is provided (can be null in some cases)
|
|
329
|
+
!excludeFolders.some((folder) => resolve(join(PROJECT_SRC, filename)).includes(folder))
|
|
330
|
+
) {
|
|
331
|
+
run(PROJECT_SRC, LIB_ICONS, PROJECT_PUBLIC, GLYPH_MAP, TARGET_FONT_TYPE, values);
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
watchers.push(watcher);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (values.watchLib) {
|
|
339
|
+
const watcher = watch(packageJsonPath, {}, async (_, filename) => {
|
|
340
|
+
const packageJson = await Bun.file(packageJsonPath).json();
|
|
341
|
+
const newLibIcons = packageJson.libraryIcons as string[];
|
|
342
|
+
|
|
343
|
+
run(PROJECT_SRC, newLibIcons, PROJECT_PUBLIC, GLYPH_MAP, TARGET_FONT_TYPE, values);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
watchers.push(watcher);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
run(PROJECT_SRC, LIB_ICONS, PROJECT_PUBLIC, GLYPH_MAP, TARGET_FONT_TYPE, values);
|
|
350
|
+
|
|
351
|
+
process.on('SIGKILL', killWatchers);
|
|
352
|
+
process.on('SIGINT', killWatchers);
|
|
353
|
+
process.on('SIGTERM', killWatchers);
|
|
354
|
+
process.on('SIGBREAK', killWatchers);
|
|
355
|
+
|
|
356
|
+
function killWatchers() {
|
|
357
|
+
console.log(`✅ The icon font generation watch process has been stopped.`);
|
|
358
|
+
|
|
359
|
+
for (let index = 0; index < watchers.length; index++) {
|
|
360
|
+
const watcher = watchers[index];
|
|
361
|
+
|
|
362
|
+
watcher.close();
|
|
363
|
+
watcher.removeAllListeners();
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
process.exit(0);
|
|
367
|
+
}
|
|
368
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export function createNameCodeObject(jsonData) {
|
|
2
|
+
const nameCodeObject = {};
|
|
3
|
+
|
|
4
|
+
for (let i = 0; i < jsonData.length; i++) {
|
|
5
|
+
const item = jsonData[i];
|
|
6
|
+
const hexCode = item.properties.code.toString(16);
|
|
7
|
+
const codePoint = parseInt(hexCode, 16);
|
|
8
|
+
const glyph = String.fromCodePoint(codePoint);
|
|
9
|
+
nameCodeObject[item.properties.ligatures] = glyph;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return nameCodeObject;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const getUnicodeObject = (jsonData) => {
|
|
16
|
+
const nameCodeObject = {};
|
|
17
|
+
|
|
18
|
+
for (let i = 0; i < jsonData.length; i++) {
|
|
19
|
+
const item = jsonData[i];
|
|
20
|
+
const hexCode = item.properties.code.toString(16);
|
|
21
|
+
const codePoint = parseInt(hexCode, 16);
|
|
22
|
+
const glyph = String.fromCodePoint(codePoint);
|
|
23
|
+
if (glyph === '') {
|
|
24
|
+
console.warn(`Invalid codepoint 0x${hexCode} for ligature ${item.properties.ligatures}`);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
nameCodeObject[item.properties.ligatures] = [glyph, 'U+' + hexCode];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return nameCodeObject;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const createCodepointObject = (jsonData) => {
|
|
34
|
+
const nameCodeObject = {};
|
|
35
|
+
|
|
36
|
+
for (let i = 0; i < jsonData.length; i++) {
|
|
37
|
+
const item = jsonData[i];
|
|
38
|
+
|
|
39
|
+
nameCodeObject[item.properties.ligatures] = item.properties.code;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return nameCodeObject;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export function formatFileSize(bytes, dm = 2) {
|
|
46
|
+
if (bytes == 0) return '0 Bytes';
|
|
47
|
+
|
|
48
|
+
const k = 1000;
|
|
49
|
+
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
50
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
51
|
+
|
|
52
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
|
53
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export function createNameCodeObject(jsonData: Item[]): Record<string, string> {
|
|
2
|
+
const nameCodeObject: Record<string, string> = {};
|
|
3
|
+
|
|
4
|
+
for (let i = 0; i < jsonData.length; i++) {
|
|
5
|
+
const item = jsonData[i];
|
|
6
|
+
const hexCode = item.properties.code.toString(16); // Convert decimal to hex
|
|
7
|
+
const codePoint = parseInt(hexCode, 16); // Parse hex to integer code point
|
|
8
|
+
const glyph = String.fromCodePoint(codePoint); // Create the glyph
|
|
9
|
+
nameCodeObject[item.properties.ligatures] = glyph;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return nameCodeObject;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const getUnicodeObject = (jsonData: Item[]): Record<string, [string, string]> => {
|
|
16
|
+
const nameCodeObject: Record<string, [string, string]> = {};
|
|
17
|
+
|
|
18
|
+
for (let i = 0; i < jsonData.length; i++) {
|
|
19
|
+
const item = jsonData[i];
|
|
20
|
+
const hexCode = item.properties.code.toString(16); // Convert decimal to hex
|
|
21
|
+
const codePoint = parseInt(hexCode, 16); // Parse hex to integer code point
|
|
22
|
+
const glyph = String.fromCodePoint(codePoint); // Create the glyph
|
|
23
|
+
if (glyph === '') {
|
|
24
|
+
console.warn(`Invalid codepoint 0x${hexCode} for ligature ${item.properties.ligatures}`);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
nameCodeObject[item.properties.ligatures] = [glyph, 'U+' + hexCode];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return nameCodeObject;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const createCodepointObject = (jsonData: Item[]): Record<string, number> => {
|
|
34
|
+
const nameCodeObject: Record<string, number> = {};
|
|
35
|
+
|
|
36
|
+
for (let i = 0; i < jsonData.length; i++) {
|
|
37
|
+
const item = jsonData[i];
|
|
38
|
+
|
|
39
|
+
nameCodeObject[item.properties.ligatures] = item.properties.code;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return nameCodeObject;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export function formatFileSize(bytes: number, dm = 2) {
|
|
46
|
+
if (bytes == 0) return '0 Bytes';
|
|
47
|
+
|
|
48
|
+
const k = 1000;
|
|
49
|
+
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
50
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
51
|
+
|
|
52
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface Icon {
|
|
56
|
+
paths: string[];
|
|
57
|
+
attrs: { fill: string; opacity?: number }[];
|
|
58
|
+
isMulticolor: boolean;
|
|
59
|
+
isMulticolor2: boolean;
|
|
60
|
+
colorPermutations: { [key: string]: { f: number }[] };
|
|
61
|
+
tags: string[];
|
|
62
|
+
grid: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface Attributes {
|
|
66
|
+
fill: string;
|
|
67
|
+
opacity?: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface Properties {
|
|
71
|
+
id: number;
|
|
72
|
+
order: number;
|
|
73
|
+
name: string;
|
|
74
|
+
ligatures: string;
|
|
75
|
+
code: number;
|
|
76
|
+
prevSize: number;
|
|
77
|
+
codes: boolean;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
interface Item {
|
|
81
|
+
icon: Icon;
|
|
82
|
+
attrs: Attributes[];
|
|
83
|
+
properties: Properties;
|
|
84
|
+
setIdx: number;
|
|
85
|
+
setId: number;
|
|
86
|
+
iconIdx: number;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type SupportedFontTypes = 'woff' | 'woff2' | 'ttf';
|
|
90
|
+
|
|
91
|
+
export type InputArguments = {
|
|
92
|
+
src: string;
|
|
93
|
+
out: string;
|
|
94
|
+
rootPath: string;
|
|
95
|
+
watch: boolean;
|
|
96
|
+
watchLib: boolean;
|
|
97
|
+
verbose: boolean;
|
|
98
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
|
2
|
+
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
|
3
|
+
{
|
|
4
|
+
"extends": "../../tsconfig.json",
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"outDir": "../../out-tsc/app",
|
|
7
|
+
"types": []
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"src/main.ts"
|
|
11
|
+
],
|
|
12
|
+
"include": [
|
|
13
|
+
"src/**/*.d.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|