@navikt/ds-css 8.10.2 → 8.10.3
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/CHANGELOG.md +6 -0
- package/dist/global/tokens.css +1 -1
- package/dist/global/tokens.min.css +1 -1
- package/dist/index.css +1 -1
- package/dist/index.min.css +1 -1
- package/package.json +12 -7
- package/types.d.ts +1 -0
- package/config/bundle.ts +0 -279
- package/config/get-version.js +0 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navikt/ds-css",
|
|
3
|
-
"version": "8.10.
|
|
3
|
+
"version": "8.10.3",
|
|
4
4
|
"description": "CSS for Nav Designsystem",
|
|
5
5
|
"author": "Aksel | Nav designsystem team",
|
|
6
6
|
"keywords": [
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"files": [
|
|
15
15
|
"*",
|
|
16
16
|
"!dist/version",
|
|
17
|
-
"!config/bundle.
|
|
17
|
+
"!config/bundle.ts",
|
|
18
|
+
"!config/get-version.js"
|
|
18
19
|
],
|
|
19
20
|
"repository": {
|
|
20
21
|
"type": "git",
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
"css:get-version": "node config/get-version.js"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
|
-
"@navikt/ds-tokens": "^8.10.
|
|
34
|
+
"@navikt/ds-tokens": "^8.10.3",
|
|
34
35
|
"browserslist": "^4.25.0",
|
|
35
36
|
"esbuild": "^0.27.4",
|
|
36
37
|
"fast-glob": "3.3.3",
|
|
@@ -46,9 +47,13 @@
|
|
|
46
47
|
],
|
|
47
48
|
"main": "./dist/index.css",
|
|
48
49
|
"exports": {
|
|
49
|
-
".":
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
".": {
|
|
51
|
+
"types": "./types.d.ts",
|
|
52
|
+
"default": "./dist/index.css"
|
|
53
|
+
},
|
|
54
|
+
"./dist/*": {
|
|
55
|
+
"types": "./types.d.ts",
|
|
56
|
+
"default": "./dist/*"
|
|
57
|
+
}
|
|
53
58
|
}
|
|
54
59
|
}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module "@navikt/ds-css" {}
|
package/config/bundle.ts
DELETED
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
import browserslist from "browserslist";
|
|
2
|
-
import esbuild from "esbuild";
|
|
3
|
-
import fastglob from "fast-glob";
|
|
4
|
-
import { Features, browserslistToTargets, bundleAsync } from "lightningcss";
|
|
5
|
-
import fs from "node:fs";
|
|
6
|
-
import path from "node:path";
|
|
7
|
-
import {
|
|
8
|
-
StyleMappings,
|
|
9
|
-
componentsCss,
|
|
10
|
-
formCss,
|
|
11
|
-
primitivesCss,
|
|
12
|
-
} from "../config/_mappings";
|
|
13
|
-
import packageJSON from "../package.json";
|
|
14
|
-
|
|
15
|
-
bundle();
|
|
16
|
-
|
|
17
|
-
async function bundle() {
|
|
18
|
-
const srcDir = path.join(__dirname, "..", "src");
|
|
19
|
-
const distDir = path.join(__dirname, "..", "dist");
|
|
20
|
-
|
|
21
|
-
const indexFileContent = fs.readFileSync(`${srcDir}/index.css`, "utf8");
|
|
22
|
-
const layerDefinition = indexFileContent
|
|
23
|
-
.split("\n")
|
|
24
|
-
.find((line) => line.startsWith("@layer"));
|
|
25
|
-
|
|
26
|
-
if (!layerDefinition) {
|
|
27
|
-
throw new Error("No layer definition found in index.css. Stopped bundling");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/* Make sure every dir is created to make node happy */
|
|
31
|
-
[distDir, `${distDir}/global`, `${distDir}/component`].forEach((dir) => {
|
|
32
|
-
if (!fs.existsSync(dir)) {
|
|
33
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Bundles the ./index.css file with LightningCSS.
|
|
39
|
-
* @param rootParser: Custom parsers that allows for editing the index.css file before bundling it. This allows removing unwanted CSS from being bundled.
|
|
40
|
-
* @returns Parsed CSS file output. Must be valid CSS.
|
|
41
|
-
*/
|
|
42
|
-
async function bundleCSS(rootParser?: (rootFile: string) => string) {
|
|
43
|
-
const { code } = await bundleAsync({
|
|
44
|
-
filename: `${srcDir}/index.css`,
|
|
45
|
-
minify: false,
|
|
46
|
-
include:
|
|
47
|
-
Features.Nesting | Features.MediaRangeSyntax | Features.HexAlphaColors,
|
|
48
|
-
|
|
49
|
-
drafts: {
|
|
50
|
-
customMedia: false,
|
|
51
|
-
},
|
|
52
|
-
targets: browserslistToTargets(
|
|
53
|
-
browserslist(">= 0.5% in NO, safari >= 15.4, iOS >= 15.4, not dead"),
|
|
54
|
-
),
|
|
55
|
-
resolver: {
|
|
56
|
-
read(filePath) {
|
|
57
|
-
const file = fs.readFileSync(filePath, "utf8");
|
|
58
|
-
if (filePath === `${srcDir}/index.css` && rootParser) {
|
|
59
|
-
return rootParser(file);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return file;
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
let codeString = code.toString();
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* LightningCSS adds these tokens to the bundle that we want removed:
|
|
71
|
-
* --lightningcss-light: initial;
|
|
72
|
-
* --lightningcss-dark: ;
|
|
73
|
-
*/
|
|
74
|
-
codeString = codeString
|
|
75
|
-
.split("\n")
|
|
76
|
-
.filter((line) => !line.includes("--lightningcss-"))
|
|
77
|
-
.join("\n");
|
|
78
|
-
|
|
79
|
-
return codeString;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Writes the CSS file to the build directory. Includes a minified version with the .min.css suffix.
|
|
84
|
-
* @param file: CSS file content
|
|
85
|
-
* @param filePath: Path to the file in the build directory
|
|
86
|
-
*/
|
|
87
|
-
function writeFile({ file, filePath }: { file: string; filePath: string }) {
|
|
88
|
-
const buildPath = `${distDir}/${filePath}`;
|
|
89
|
-
fs.writeFileSync(buildPath, file);
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* We use Esbuild package here since we only want it to optimize filesize, not transform any CSS like LightningCSS minifier does.
|
|
93
|
-
* This is because we want to keep the CSS as close to the original as possible.
|
|
94
|
-
*/
|
|
95
|
-
const result = esbuild.buildSync({
|
|
96
|
-
entryPoints: [buildPath],
|
|
97
|
-
outfile: buildPath.replace(".css", ".min.css"),
|
|
98
|
-
minify: true, // Enable minification
|
|
99
|
-
bundle: false,
|
|
100
|
-
write: true,
|
|
101
|
-
format: "iife",
|
|
102
|
-
loader: {
|
|
103
|
-
".css": "css",
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
if (result.errors.length > 0) {
|
|
108
|
-
throw new Error(
|
|
109
|
-
`Errors found when minifying for ${filePath} CSS. Stopped bundling\n${result.errors}`,
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/* ----------------------------- index.css build ---------------------------- */
|
|
115
|
-
await bundleCSS().then((file) => {
|
|
116
|
-
writeFile({
|
|
117
|
-
file,
|
|
118
|
-
filePath: "index.css",
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
/* --------------------------- component.css build -------------------------- */
|
|
123
|
-
function rootComponentsParser(rootString: string) {
|
|
124
|
-
let parsed = rootString
|
|
125
|
-
.split("\n")
|
|
126
|
-
.filter((line) => {
|
|
127
|
-
/* We assume that all components is added under the layer components or layout */
|
|
128
|
-
return (
|
|
129
|
-
line.includes("layer(aksel.components") ||
|
|
130
|
-
line.includes("layer(aksel.layout")
|
|
131
|
-
);
|
|
132
|
-
})
|
|
133
|
-
.join("\n");
|
|
134
|
-
|
|
135
|
-
parsed = layerDefinition + "\n" + parsed;
|
|
136
|
-
|
|
137
|
-
return parsed;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
await bundleCSS(rootComponentsParser).then((file) => {
|
|
141
|
-
writeFile({
|
|
142
|
-
file,
|
|
143
|
-
filePath: componentsCss,
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
/* ------------------------------ /global build ----------------------------- */
|
|
148
|
-
for (const style of StyleMappings.baseline) {
|
|
149
|
-
function parser(input: string) {
|
|
150
|
-
const parsed = input
|
|
151
|
-
.split("\n")
|
|
152
|
-
.filter((line) => line.startsWith("@import"))
|
|
153
|
-
.filter((line) => line.includes(style.main))
|
|
154
|
-
.join("\n");
|
|
155
|
-
return layerDefinition + "\n" + parsed;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
await bundleCSS(parser).then((file) => {
|
|
159
|
-
writeFile({
|
|
160
|
-
file,
|
|
161
|
-
filePath: `global/${style.main}`,
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/* ------------------------------ form build ----------------------------- */
|
|
167
|
-
function rootFormParser(input: string) {
|
|
168
|
-
const parsed = input
|
|
169
|
-
.split("\n")
|
|
170
|
-
.filter((line) => line.startsWith("@import"))
|
|
171
|
-
.filter((line) => line.includes("form/index.css"))
|
|
172
|
-
.join("\n");
|
|
173
|
-
return layerDefinition + "\n" + parsed;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
await bundleCSS(rootFormParser).then((file) => {
|
|
177
|
-
writeFile({
|
|
178
|
-
file,
|
|
179
|
-
filePath: `component/${formCss}`,
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
/* ------------------------------ Primitives build ----------------------------- */
|
|
184
|
-
function rootPrimitivesParser(input: string) {
|
|
185
|
-
const parsed = input
|
|
186
|
-
.split("\n")
|
|
187
|
-
.filter((line) => line.startsWith("@import"))
|
|
188
|
-
.filter((line) => line.includes("primitives/index.css"))
|
|
189
|
-
.join("\n");
|
|
190
|
-
return layerDefinition + "\n" + parsed;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
await bundleCSS(rootPrimitivesParser).then((file) => {
|
|
194
|
-
writeFile({
|
|
195
|
-
file,
|
|
196
|
-
filePath: `component/${primitivesCss}`,
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
/* ---------------------------- /component build ---------------------------- */
|
|
201
|
-
|
|
202
|
-
function componentFiles(): string[] {
|
|
203
|
-
const indexFile = indexFileContent;
|
|
204
|
-
|
|
205
|
-
/* Since forms and primitives is under the same layers, but diffferent files we filter them out to avoid duplicates */
|
|
206
|
-
const formLine = rootFormParser(indexFile);
|
|
207
|
-
const primitivesLine = rootPrimitivesParser(indexFile);
|
|
208
|
-
|
|
209
|
-
return indexFile
|
|
210
|
-
.split("\n")
|
|
211
|
-
.filter((line) => line.startsWith("@import"))
|
|
212
|
-
.filter((line) => !formLine.includes(line))
|
|
213
|
-
.filter((line) => !primitivesLine.includes(line))
|
|
214
|
-
.filter((line) => line.includes("layer(aksel.components"));
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
for (const componentLine of componentFiles()) {
|
|
218
|
-
function parser(input: string) {
|
|
219
|
-
const parsed = input
|
|
220
|
-
.split("\n")
|
|
221
|
-
.filter((line) => line === componentLine)
|
|
222
|
-
.join("\n");
|
|
223
|
-
return layerDefinition + "\n" + parsed;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
await bundleCSS(parser).then((file) => {
|
|
227
|
-
const componentName = componentLine
|
|
228
|
-
/* Matches everything between " */
|
|
229
|
-
.match(/".*"/gm)?.[0]
|
|
230
|
-
/* Replaces every " with nothing */
|
|
231
|
-
.replace(/"/gm, "")
|
|
232
|
-
/* Removes start of import-string */
|
|
233
|
-
.replace("./", "");
|
|
234
|
-
|
|
235
|
-
if (!componentName) {
|
|
236
|
-
throw new Error(
|
|
237
|
-
`Could not find component name for line: ${componentLine}`,
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const sanitizedName = componentName
|
|
242
|
-
/*
|
|
243
|
-
* https://regex101.com/r/MAj58n/1
|
|
244
|
-
* Removes every - and space
|
|
245
|
-
*/
|
|
246
|
-
.replace(/[\s-]/g, "")
|
|
247
|
-
.replace(".css", "")
|
|
248
|
-
.toLowerCase();
|
|
249
|
-
|
|
250
|
-
writeFile({
|
|
251
|
-
file,
|
|
252
|
-
filePath: `component/${sanitizedName}.css`,
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
const version = packageJSON.version;
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* We only publish
|
|
261
|
-
* - index.css
|
|
262
|
-
* - index.min.css
|
|
263
|
-
*
|
|
264
|
-
* to CDNs with versioning
|
|
265
|
-
*/
|
|
266
|
-
const files = fastglob.sync("**/index*.css", {
|
|
267
|
-
cwd: distDir,
|
|
268
|
-
ignore: ["**/version/**"],
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
for (const file of files) {
|
|
272
|
-
const css = fs.readFileSync(`${distDir}/${file}`, "utf-8");
|
|
273
|
-
|
|
274
|
-
const filename = `${distDir}/version/${version}/${file}`;
|
|
275
|
-
fs.mkdirSync(path.dirname(filename), { recursive: true });
|
|
276
|
-
|
|
277
|
-
fs.writeFileSync(filename, css);
|
|
278
|
-
}
|
|
279
|
-
}
|
package/config/get-version.js
DELETED