|
1 | | -import { convertType } from "./convert-type"; |
2 | | -import { toCamelCase } from "./to-camelcase"; |
3 | | -import { toPascalCase } from "./to-pascalcase"; |
| 1 | +import { convertType } from './convert-type' |
| 2 | +import { toCamelCase } from './to-camelcase' |
| 3 | +import { toPascalCase } from './to-pascalcase' |
4 | 4 |
|
5 | | -let output = `export as namespace CSS;\nexport interface CustomColors{}\n`; |
| 5 | +let output = `/** biome-ignore-all lint/complexity/noBannedTypes: <this is a generated file> */\nexport as namespace CSS;\nexport interface CustomColors{}\n` |
6 | 6 |
|
7 | 7 | const syntaxes = (await fetch( |
8 | | - "https://raw.githubusercontent.com/mdn/data/refs/heads/main/css/syntaxes.json", |
| 8 | + 'https://raw.githubusercontent.com/mdn/data/refs/heads/main/css/syntaxes.json', |
9 | 9 | ).then((res) => res.json())) as Record< |
10 | | - string, |
11 | | - { |
12 | | - syntax: string; |
13 | | - primitive?: boolean; |
14 | | - } |
15 | | ->; |
| 10 | + string, |
| 11 | + { |
| 12 | + syntax: string |
| 13 | + primitive?: boolean |
| 14 | + } |
| 15 | +> |
16 | 16 |
|
17 | 17 | const properties = (await fetch( |
18 | | - "https://raw.githubusercontent.com/mdn/data/refs/heads/main/css/properties.json", |
| 18 | + 'https://raw.githubusercontent.com/mdn/data/refs/heads/main/css/properties.json', |
19 | 19 | ).then((res) => res.json())) as Record< |
20 | | - string, |
21 | | - { |
22 | | - syntax: string; |
23 | | - status: string; |
24 | | - } |
25 | | ->; |
| 20 | + string, |
| 21 | + { |
| 22 | + syntax: string |
| 23 | + status: string |
| 24 | + } |
| 25 | +> |
26 | 26 |
|
27 | 27 | const customSyntaxes = { |
28 | | - string: { |
29 | | - syntax: "(string & {})", |
30 | | - primitive: true, |
31 | | - }, |
32 | | - number: { |
33 | | - syntax: "number", |
34 | | - primitive: true, |
35 | | - }, |
36 | | - percentage: { |
37 | | - syntax: "number", |
38 | | - primitive: true, |
39 | | - }, |
40 | | - integer: { |
41 | | - syntax: "number", |
42 | | - primitive: true, |
43 | | - }, |
44 | | -}; |
| 28 | + string: { |
| 29 | + syntax: '(string & {})', |
| 30 | + primitive: true, |
| 31 | + }, |
| 32 | + number: { |
| 33 | + syntax: 'number', |
| 34 | + primitive: true, |
| 35 | + }, |
| 36 | + percentage: { |
| 37 | + syntax: 'number', |
| 38 | + primitive: true, |
| 39 | + }, |
| 40 | + integer: { |
| 41 | + syntax: 'number', |
| 42 | + primitive: true, |
| 43 | + }, |
| 44 | +} |
45 | 45 |
|
46 | | -Object.assign(syntaxes, customSyntaxes); |
| 46 | +Object.assign(syntaxes, customSyntaxes) |
47 | 47 |
|
48 | | -const standardProperties: string[] = []; |
49 | | -const vendorProperties: [string, { syntax: string; status: string }][] = []; |
| 48 | +const standardProperties: string[] = [] |
| 49 | +const vendorProperties: [string, { syntax: string; status: string }][] = [] |
50 | 50 | for (const [property, value] of Object.entries(properties)) { |
51 | | - // skip vendor prefixed properties |
52 | | - if (property.startsWith("--")) continue; |
53 | | - if ( |
54 | | - property.startsWith("-ms-") || |
55 | | - property.startsWith("-webkit-") || |
56 | | - property.startsWith("-moz-") |
57 | | - ) { |
58 | | - vendorProperties.push([property, value]); |
59 | | - continue; |
60 | | - } |
61 | | - if (value.status !== "standard") continue; |
62 | | - output += `export type ${toPascalCase(property)} = ${convertType(value.syntax, syntaxes)};\n`; |
63 | | - standardProperties.push(property); |
| 51 | + // skip vendor prefixed properties |
| 52 | + if (property.startsWith('--')) continue |
| 53 | + if ( |
| 54 | + property.startsWith('-ms-') || |
| 55 | + property.startsWith('-webkit-') || |
| 56 | + property.startsWith('-moz-') |
| 57 | + ) { |
| 58 | + vendorProperties.push([property, value]) |
| 59 | + continue |
| 60 | + } |
| 61 | + if (value.status !== 'standard') continue |
| 62 | + output += `export type ${toPascalCase(property)} = ${convertType(value.syntax, syntaxes)};\n` |
| 63 | + standardProperties.push(property) |
64 | 64 | } |
65 | 65 |
|
66 | 66 | output += `export interface StandardProperties { |
67 | | -${standardProperties.map((p) => ` ${toCamelCase(p)}: ${toPascalCase(p)}`).join("\n")} |
68 | | -}\n`; |
| 67 | +${standardProperties.map((p) => ` ${toCamelCase(p)}: ${toPascalCase(p)}`).join('\n')} |
| 68 | +}\n` |
69 | 69 |
|
70 | 70 | for (const [property, value] of vendorProperties) { |
71 | | - output += `export type ${toPascalCase(property)} = ${convertType(value.syntax, syntaxes)};\n`; |
| 71 | + output += `export type ${toPascalCase(property)} = ${convertType(value.syntax, syntaxes)};\n` |
72 | 72 | } |
73 | 73 |
|
74 | 74 | output += `export interface VendorProperties { |
75 | | -${vendorProperties.map(([p, _]) => ` ${toCamelCase(p)}: ${toPascalCase(p)}`).join("\n")} |
76 | | -}\n`; |
| 75 | +${vendorProperties.map(([p, _]) => ` ${toCamelCase(p)}: ${toPascalCase(p)}`).join('\n')} |
| 76 | +}\n` |
77 | 77 |
|
78 | 78 | for (const [property, value] of Object.entries(syntaxes)) { |
79 | | - if ( |
80 | | - property.endsWith(")") || |
81 | | - property.includes("+") || |
82 | | - value.syntax.includes("@") |
83 | | - ) |
84 | | - continue; |
85 | | - if (property in customSyntaxes) { |
86 | | - continue; |
87 | | - } |
88 | | - output += `export type T${toPascalCase(property)} = ${convertType(value.syntax.replace("<image |", "<image> |"), syntaxes)}${property === "color" ? " | keyof CustomColors" : ""};\n`; |
| 79 | + if ( |
| 80 | + property.endsWith(')') || |
| 81 | + property.includes('+') || |
| 82 | + value.syntax.includes('@') |
| 83 | + ) |
| 84 | + continue |
| 85 | + if (property in customSyntaxes) { |
| 86 | + continue |
| 87 | + } |
| 88 | + output += `export type T${toPascalCase(property)} = ${convertType(value.syntax.replace('<image |', '<image> |'), syntaxes)}${property === 'color' ? ' | keyof CustomColors' : ''};\n` |
89 | 89 | } |
90 | 90 |
|
91 | | -Bun.write("src/index.d.ts", output); |
| 91 | +Bun.write('src/index.d.ts', output) |
92 | 92 |
|
93 | 93 | // declare module "./src" { |
94 | 94 | // interface CustomColors { |
|
0 commit comments