@navita/css 0.2.0 → 3.0.0-next.0
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/_virtual/_rolldown/runtime.cjs +23 -0
- package/fontFace.cjs +5 -6
- package/fontFace.mjs +7 -4
- package/globalStyle.cjs +5 -6
- package/globalStyle.mjs +7 -4
- package/helpers/walkObject.cjs +11 -17
- package/helpers/walkObject.mjs +13 -15
- package/index.cjs +63 -64
- package/index.d.ts +24 -15
- package/index.mjs +54 -51
- package/keyframes.cjs +5 -6
- package/keyframes.mjs +7 -4
- package/merge.cjs +10 -10
- package/merge.mjs +12 -8
- package/package.json +2 -2
- package/style.cjs +5 -6
- package/style.mjs +7 -4
- package/theme.cjs +25 -34
- package/theme.mjs +25 -32
- package/validateContract.cjs +34 -48
- package/validateContract.mjs +36 -46
- package/vars.cjs +28 -38
- package/vars.mjs +28 -36
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.__toESM = __toESM;
|
package/fontFace.cjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _navita_adapter = require("@navita/adapter");
|
|
3
|
+
//#region src/fontFace.ts
|
|
5
4
|
function fontFace(rule) {
|
|
6
|
-
|
|
5
|
+
return (0, _navita_adapter.addFontFace)(rule);
|
|
7
6
|
}
|
|
8
|
-
|
|
7
|
+
//#endregion
|
|
9
8
|
exports.fontFace = fontFace;
|
package/fontFace.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import "node:path";
|
|
2
|
+
import "node:url";
|
|
3
|
+
import.meta.url;
|
|
4
|
+
import { addFontFace } from "@navita/adapter";
|
|
5
|
+
//#region src/fontFace.ts
|
|
3
6
|
function fontFace(rule) {
|
|
4
|
-
|
|
7
|
+
return addFontFace(rule);
|
|
5
8
|
}
|
|
6
|
-
|
|
9
|
+
//#endregion
|
|
7
10
|
export { fontFace };
|
package/globalStyle.cjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _navita_adapter = require("@navita/adapter");
|
|
3
|
+
//#region src/globalStyle.ts
|
|
5
4
|
function globalStyle(selector, rule) {
|
|
6
|
-
|
|
5
|
+
(0, _navita_adapter.addStaticCss)(selector, rule);
|
|
7
6
|
}
|
|
8
|
-
|
|
7
|
+
//#endregion
|
|
9
8
|
exports.globalStyle = globalStyle;
|
package/globalStyle.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import "node:path";
|
|
2
|
+
import "node:url";
|
|
3
|
+
import.meta.url;
|
|
4
|
+
import { addStaticCss } from "@navita/adapter";
|
|
5
|
+
//#region src/globalStyle.ts
|
|
3
6
|
function globalStyle(selector, rule) {
|
|
4
|
-
|
|
7
|
+
addStaticCss(selector, rule);
|
|
5
8
|
}
|
|
6
|
-
|
|
9
|
+
//#endregion
|
|
7
10
|
export { globalStyle };
|
package/helpers/walkObject.cjs
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/helpers/walkObject.ts
|
|
3
3
|
function walkObject(objectToWalk, transformFn, currentPath = []) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
clonedObject[key] = transformFn(value, newPath);
|
|
13
|
-
} else if (typeof value === 'object' && !Array.isArray(value)) {
|
|
14
|
-
clonedObject[key] = walkObject(value, transformFn, newPath);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return clonedObject;
|
|
4
|
+
const clonedObject = objectToWalk.constructor();
|
|
5
|
+
for (const key in objectToWalk) {
|
|
6
|
+
const value = objectToWalk[key];
|
|
7
|
+
const newPath = [...currentPath, key];
|
|
8
|
+
if (typeof value === "string" || typeof value === "number" || value == null) clonedObject[key] = transformFn(value, newPath);
|
|
9
|
+
else if (typeof value === "object" && !Array.isArray(value)) clonedObject[key] = walkObject(value, transformFn, newPath);
|
|
10
|
+
}
|
|
11
|
+
return clonedObject;
|
|
18
12
|
}
|
|
19
|
-
|
|
13
|
+
//#endregion
|
|
20
14
|
exports.walkObject = walkObject;
|
package/helpers/walkObject.mjs
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
+
import "node:path";
|
|
2
|
+
import "node:url";
|
|
3
|
+
import.meta.url;
|
|
4
|
+
//#region src/helpers/walkObject.ts
|
|
1
5
|
function walkObject(objectToWalk, transformFn, currentPath = []) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
clonedObject[key] = transformFn(value, newPath);
|
|
11
|
-
} else if (typeof value === 'object' && !Array.isArray(value)) {
|
|
12
|
-
clonedObject[key] = walkObject(value, transformFn, newPath);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return clonedObject;
|
|
6
|
+
const clonedObject = objectToWalk.constructor();
|
|
7
|
+
for (const key in objectToWalk) {
|
|
8
|
+
const value = objectToWalk[key];
|
|
9
|
+
const newPath = [...currentPath, key];
|
|
10
|
+
if (typeof value === "string" || typeof value === "number" || value == null) clonedObject[key] = transformFn(value, newPath);
|
|
11
|
+
else if (typeof value === "object" && !Array.isArray(value)) clonedObject[key] = walkObject(value, transformFn, newPath);
|
|
12
|
+
}
|
|
13
|
+
return clonedObject;
|
|
16
14
|
}
|
|
17
|
-
|
|
15
|
+
//#endregion
|
|
18
16
|
export { walkObject };
|
package/index.cjs
CHANGED
|
@@ -1,67 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const source = '@navita/css';
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_fontFace = require("./fontFace.cjs");
|
|
3
|
+
const require_globalStyle = require("./globalStyle.cjs");
|
|
4
|
+
const require_keyframes = require("./keyframes.cjs");
|
|
5
|
+
const require_merge = require("./merge.cjs");
|
|
6
|
+
const require_style = require("./style.cjs");
|
|
7
|
+
const require_vars = require("./vars.cjs");
|
|
8
|
+
const require_theme = require("./theme.cjs");
|
|
9
|
+
//#region src/index.ts
|
|
10
|
+
const source = "@navita/css";
|
|
12
11
|
const importMap = [
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
12
|
+
{
|
|
13
|
+
callee: "style",
|
|
14
|
+
source
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
callee: "globalStyle",
|
|
18
|
+
source
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
callee: "keyframes",
|
|
22
|
+
source
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
callee: "fontFace",
|
|
26
|
+
source
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
callee: "createThemeContract",
|
|
30
|
+
source
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
callee: "createGlobalThemeContract",
|
|
34
|
+
source
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
callee: "createGlobalTheme",
|
|
38
|
+
source
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
callee: "createTheme",
|
|
42
|
+
source
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
callee: "createVar",
|
|
46
|
+
source
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
callee: "fallbackVar",
|
|
50
|
+
source
|
|
51
|
+
}
|
|
53
52
|
];
|
|
54
|
-
|
|
55
|
-
exports.
|
|
56
|
-
exports.
|
|
57
|
-
exports.
|
|
58
|
-
exports.
|
|
59
|
-
exports.
|
|
60
|
-
exports.
|
|
61
|
-
exports.
|
|
62
|
-
exports.
|
|
63
|
-
exports.
|
|
64
|
-
exports.assignVars = vars.assignVars;
|
|
65
|
-
exports.createVar = vars.createVar;
|
|
66
|
-
exports.fallbackVar = vars.fallbackVar;
|
|
53
|
+
//#endregion
|
|
54
|
+
exports.assignVars = require_vars.assignVars;
|
|
55
|
+
exports.createGlobalTheme = require_theme.createGlobalTheme;
|
|
56
|
+
exports.createGlobalThemeContract = require_theme.createGlobalThemeContract;
|
|
57
|
+
exports.createTheme = require_theme.createTheme;
|
|
58
|
+
exports.createThemeContract = require_theme.createThemeContract;
|
|
59
|
+
exports.createVar = require_vars.createVar;
|
|
60
|
+
exports.fallbackVar = require_vars.fallbackVar;
|
|
61
|
+
exports.fontFace = require_fontFace.fontFace;
|
|
62
|
+
exports.globalStyle = require_globalStyle.globalStyle;
|
|
67
63
|
exports.importMap = importMap;
|
|
64
|
+
exports.keyframes = require_keyframes.keyframes;
|
|
65
|
+
exports.merge = require_merge.merge;
|
|
66
|
+
exports.style = require_style.style;
|
package/index.d.ts
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare function style(rule: StyleRule): string;
|
|
1
|
+
import { CSSKeyframes, CSSVarFunction, Contract, FontFaceRule, GlobalStyleRule, MapLeafNodes, NullableTokens, StyleRule, ThemeVars, Tokens } from "@navita/types";
|
|
2
|
+
export type * from "@navita/types";
|
|
4
3
|
|
|
4
|
+
//#region src/fontFace.d.ts
|
|
5
|
+
declare function fontFace(rule: FontFaceRule | FontFaceRule[]): string;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/globalStyle.d.ts
|
|
5
8
|
declare function globalStyle(selector: string, rule: GlobalStyleRule): void;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/keyframes.d.ts
|
|
9
11
|
declare function keyframes(rule: CSSKeyframes): string;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/merge.d.ts
|
|
14
|
+
declare function merge(...classNames: (string | false | void | null | 0 | "")[]): string;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/style.d.ts
|
|
17
|
+
declare function style(rule: StyleRule): string;
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/theme.d.ts
|
|
13
20
|
declare function createThemeContract<ThemeTokens extends NullableTokens>(tokens: ThemeTokens): ThemeVars<ThemeTokens>;
|
|
14
21
|
declare function createGlobalThemeContract<ThemeTokens extends Tokens>(tokens: ThemeTokens): ThemeVars<ThemeTokens>;
|
|
15
22
|
declare function createGlobalThemeContract<ThemeTokens extends NullableTokens>(tokens: ThemeTokens, mapFn: (value: string | null, path: Array<string>) => string): ThemeVars<ThemeTokens>;
|
|
@@ -17,14 +24,16 @@ declare function createGlobalTheme<ThemeTokens extends Tokens>(selector: string,
|
|
|
17
24
|
declare function createGlobalTheme<ThemeContract extends Contract>(selector: string, themeContract: ThemeContract, tokens: MapLeafNodes<ThemeContract, string>): void;
|
|
18
25
|
declare function createTheme<ThemeTokens extends Tokens>(tokens: ThemeTokens, debugId?: string): [className: string, vars: ThemeVars<ThemeTokens>];
|
|
19
26
|
declare function createTheme<ThemeContract extends Contract>(themeContract: ThemeContract, tokens: MapLeafNodes<ThemeContract, string>): string;
|
|
20
|
-
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/vars.d.ts
|
|
21
29
|
declare function createVar<T extends string>(name?: T): `--${T}`;
|
|
22
30
|
declare function fallbackVar(...values: [string, ...Array<string>]): string;
|
|
23
31
|
declare function assignVars<VarContract extends Contract>(varContract: VarContract, tokens: MapLeafNodes<VarContract, string>): Record<CSSVarFunction, string>;
|
|
24
|
-
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/index.d.ts
|
|
25
34
|
declare const importMap: {
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
callee: string;
|
|
36
|
+
source: string;
|
|
28
37
|
}[];
|
|
29
|
-
|
|
30
|
-
export { assignVars, createGlobalTheme, createGlobalThemeContract, createTheme, createThemeContract, createVar, fallbackVar, fontFace, globalStyle, importMap, keyframes, merge, style };
|
|
38
|
+
//#endregion
|
|
39
|
+
export { assignVars, createGlobalTheme, createGlobalThemeContract, createTheme, createThemeContract, createVar, fallbackVar, fontFace, globalStyle, importMap, keyframes, merge, style };
|
package/index.mjs
CHANGED
|
@@ -1,53 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import "node:path";
|
|
2
|
+
import "node:url";
|
|
3
|
+
import.meta.url;
|
|
4
|
+
import { fontFace } from "./fontFace.mjs";
|
|
5
|
+
import { globalStyle } from "./globalStyle.mjs";
|
|
6
|
+
import { keyframes } from "./keyframes.mjs";
|
|
7
|
+
import { merge } from "./merge.mjs";
|
|
8
|
+
import { style } from "./style.mjs";
|
|
9
|
+
import { assignVars, createVar, fallbackVar } from "./vars.mjs";
|
|
10
|
+
import { createGlobalTheme, createGlobalThemeContract, createTheme, createThemeContract } from "./theme.mjs";
|
|
11
|
+
//#region src/index.ts
|
|
12
|
+
const source = "@navita/css";
|
|
10
13
|
const importMap = [
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
14
|
+
{
|
|
15
|
+
callee: "style",
|
|
16
|
+
source
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
callee: "globalStyle",
|
|
20
|
+
source
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
callee: "keyframes",
|
|
24
|
+
source
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
callee: "fontFace",
|
|
28
|
+
source
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
callee: "createThemeContract",
|
|
32
|
+
source
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
callee: "createGlobalThemeContract",
|
|
36
|
+
source
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
callee: "createGlobalTheme",
|
|
40
|
+
source
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
callee: "createTheme",
|
|
44
|
+
source
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
callee: "createVar",
|
|
48
|
+
source
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
callee: "fallbackVar",
|
|
52
|
+
source
|
|
53
|
+
}
|
|
51
54
|
];
|
|
52
|
-
|
|
53
|
-
export { importMap };
|
|
55
|
+
//#endregion
|
|
56
|
+
export { assignVars, createGlobalTheme, createGlobalThemeContract, createTheme, createThemeContract, createVar, fallbackVar, fontFace, globalStyle, importMap, keyframes, merge, style };
|
package/keyframes.cjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _navita_adapter = require("@navita/adapter");
|
|
3
|
+
//#region src/keyframes.ts
|
|
5
4
|
function keyframes(rule) {
|
|
6
|
-
|
|
5
|
+
return (0, _navita_adapter.addKeyframe)(rule);
|
|
7
6
|
}
|
|
8
|
-
|
|
7
|
+
//#endregion
|
|
9
8
|
exports.keyframes = keyframes;
|
package/keyframes.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import "node:path";
|
|
2
|
+
import "node:url";
|
|
3
|
+
import.meta.url;
|
|
4
|
+
import { addKeyframe } from "@navita/adapter";
|
|
5
|
+
//#region src/keyframes.ts
|
|
3
6
|
function keyframes(rule) {
|
|
4
|
-
|
|
7
|
+
return addKeyframe(rule);
|
|
5
8
|
}
|
|
6
|
-
|
|
9
|
+
//#endregion
|
|
7
10
|
export { keyframes };
|
package/merge.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/merge.ts
|
|
3
3
|
function merge(...classNames) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
const input = classNames.filter(Boolean).join(" ").split(" ");
|
|
5
|
+
const output = {};
|
|
6
|
+
for (const className of input) {
|
|
7
|
+
const [property] = className.split(/\d+$/);
|
|
8
|
+
output[property] = className;
|
|
9
|
+
}
|
|
10
|
+
return Object.values(output).join(" ");
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
//#endregion
|
|
13
13
|
exports.merge = merge;
|
package/merge.mjs
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import "node:path";
|
|
2
|
+
import "node:url";
|
|
3
|
+
import.meta.url;
|
|
4
|
+
//#region src/merge.ts
|
|
1
5
|
function merge(...classNames) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const input = classNames.filter(Boolean).join(" ").split(" ");
|
|
7
|
+
const output = {};
|
|
8
|
+
for (const className of input) {
|
|
9
|
+
const [property] = className.split(/\d+$/);
|
|
10
|
+
output[property] = className;
|
|
11
|
+
}
|
|
12
|
+
return Object.values(output).join(" ");
|
|
9
13
|
}
|
|
10
|
-
|
|
14
|
+
//#endregion
|
|
11
15
|
export { merge };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navita/css",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "3.0.0-next.0",
|
|
4
4
|
"description": "Public API for Navita",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"deep-object-diff": "^1.1.9",
|
|
22
22
|
"cssesc": "^3.0.0",
|
|
23
|
-
"@navita/adapter": "0.
|
|
23
|
+
"@navita/adapter": "3.0.0-next.0"
|
|
24
24
|
},
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"author": "Eagerpatch",
|
package/style.cjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _navita_adapter = require("@navita/adapter");
|
|
3
|
+
//#region src/style.ts
|
|
5
4
|
function style(rule) {
|
|
6
|
-
|
|
5
|
+
return (0, _navita_adapter.addCss)(rule);
|
|
7
6
|
}
|
|
8
|
-
|
|
7
|
+
//#endregion
|
|
9
8
|
exports.style = style;
|
package/style.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import "node:path";
|
|
2
|
+
import "node:url";
|
|
3
|
+
import.meta.url;
|
|
4
|
+
import { addCss } from "@navita/adapter";
|
|
5
|
+
//#region src/style.ts
|
|
3
6
|
function style(rule) {
|
|
4
|
-
|
|
7
|
+
return addCss(rule);
|
|
5
8
|
}
|
|
6
|
-
|
|
9
|
+
//#endregion
|
|
7
10
|
export { style };
|
package/theme.cjs
CHANGED
|
@@ -1,45 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_helpers_walkObject = require("./helpers/walkObject.cjs");
|
|
4
|
+
const require_vars = require("./vars.cjs");
|
|
5
|
+
let _navita_adapter = require("@navita/adapter");
|
|
6
|
+
let cssesc = require("cssesc");
|
|
7
|
+
cssesc = require_runtime.__toESM(cssesc);
|
|
8
|
+
//#region src/theme.ts
|
|
8
9
|
function createThemeContract(tokens) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
return require_helpers_walkObject.walkObject(tokens, (_value, path) => {
|
|
11
|
+
return `var(${require_vars.createVar(path.join("-").toLowerCase())})`;
|
|
12
|
+
});
|
|
12
13
|
}
|
|
13
14
|
function createGlobalThemeContract(tokens, mapFn) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
throw new Error(`Invalid variable name for "${path.join('.')}": ${varName}`);
|
|
21
|
-
}
|
|
22
|
-
return `var(--${varName})`;
|
|
23
|
-
});
|
|
15
|
+
return require_helpers_walkObject.walkObject(tokens, (value, path) => {
|
|
16
|
+
const rawVarName = typeof mapFn === "function" ? mapFn(value, path) : value;
|
|
17
|
+
const varName = typeof rawVarName === "string" ? rawVarName.replace(/^--/, "") : null;
|
|
18
|
+
if (typeof varName !== "string" || varName !== (0, cssesc.default)(varName, { isIdentifier: true })) throw new Error(`Invalid variable name for "${path.join(".")}": ${varName}`);
|
|
19
|
+
return `var(--${varName})`;
|
|
20
|
+
});
|
|
24
21
|
}
|
|
25
22
|
function createGlobalTheme(selector, arg2, arg3) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (shouldCreateVars) {
|
|
31
|
-
return themeVars;
|
|
32
|
-
}
|
|
23
|
+
const shouldCreateVars = Boolean(!arg3);
|
|
24
|
+
const themeVars = shouldCreateVars ? createThemeContract(arg2) : arg2;
|
|
25
|
+
(0, _navita_adapter.addStaticCss)(selector, require_vars.assignVars(themeVars, shouldCreateVars ? arg2 : arg3));
|
|
26
|
+
if (shouldCreateVars) return themeVars;
|
|
33
27
|
}
|
|
34
28
|
function createTheme(arg1, arg2) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
themeClassName,
|
|
39
|
-
vars
|
|
40
|
-
] : themeClassName;
|
|
29
|
+
const themeClassName = (0, _navita_adapter.generateIdentifier)(typeof arg2 === "object" ? arg2 : arg1);
|
|
30
|
+
const vars = typeof arg2 === "object" ? createGlobalTheme(`.${themeClassName}`, arg1, arg2) : createGlobalTheme(`.${themeClassName}`, arg1);
|
|
31
|
+
return vars ? [themeClassName, vars] : themeClassName;
|
|
41
32
|
}
|
|
42
|
-
|
|
33
|
+
//#endregion
|
|
43
34
|
exports.createGlobalTheme = createGlobalTheme;
|
|
44
35
|
exports.createGlobalThemeContract = createGlobalThemeContract;
|
|
45
36
|
exports.createTheme = createTheme;
|
package/theme.mjs
CHANGED
|
@@ -1,41 +1,34 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import "node:path";
|
|
2
|
+
import "node:url";
|
|
3
|
+
import.meta.url;
|
|
4
|
+
import { walkObject } from "./helpers/walkObject.mjs";
|
|
5
|
+
import { assignVars, createVar } from "./vars.mjs";
|
|
6
|
+
import { addStaticCss, generateIdentifier } from "@navita/adapter";
|
|
7
|
+
import cssesc from "cssesc";
|
|
8
|
+
//#region src/theme.ts
|
|
6
9
|
function createThemeContract(tokens) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
return walkObject(tokens, (_value, path) => {
|
|
11
|
+
return `var(${createVar(path.join("-").toLowerCase())})`;
|
|
12
|
+
});
|
|
10
13
|
}
|
|
11
14
|
function createGlobalThemeContract(tokens, mapFn) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
throw new Error(`Invalid variable name for "${path.join('.')}": ${varName}`);
|
|
19
|
-
}
|
|
20
|
-
return `var(--${varName})`;
|
|
21
|
-
});
|
|
15
|
+
return walkObject(tokens, (value, path) => {
|
|
16
|
+
const rawVarName = typeof mapFn === "function" ? mapFn(value, path) : value;
|
|
17
|
+
const varName = typeof rawVarName === "string" ? rawVarName.replace(/^--/, "") : null;
|
|
18
|
+
if (typeof varName !== "string" || varName !== cssesc(varName, { isIdentifier: true })) throw new Error(`Invalid variable name for "${path.join(".")}": ${varName}`);
|
|
19
|
+
return `var(--${varName})`;
|
|
20
|
+
});
|
|
22
21
|
}
|
|
23
22
|
function createGlobalTheme(selector, arg2, arg3) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (shouldCreateVars) {
|
|
29
|
-
return themeVars;
|
|
30
|
-
}
|
|
23
|
+
const shouldCreateVars = Boolean(!arg3);
|
|
24
|
+
const themeVars = shouldCreateVars ? createThemeContract(arg2) : arg2;
|
|
25
|
+
addStaticCss(selector, assignVars(themeVars, shouldCreateVars ? arg2 : arg3));
|
|
26
|
+
if (shouldCreateVars) return themeVars;
|
|
31
27
|
}
|
|
32
28
|
function createTheme(arg1, arg2) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
themeClassName,
|
|
37
|
-
vars
|
|
38
|
-
] : themeClassName;
|
|
29
|
+
const themeClassName = generateIdentifier(typeof arg2 === "object" ? arg2 : arg1);
|
|
30
|
+
const vars = typeof arg2 === "object" ? createGlobalTheme(`.${themeClassName}`, arg1, arg2) : createGlobalTheme(`.${themeClassName}`, arg1);
|
|
31
|
+
return vars ? [themeClassName, vars] : themeClassName;
|
|
39
32
|
}
|
|
40
|
-
|
|
33
|
+
//#endregion
|
|
41
34
|
export { createGlobalTheme, createGlobalThemeContract, createTheme, createThemeContract };
|
package/validateContract.cjs
CHANGED
|
@@ -1,55 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const normaliseObject = (obj)=>walkObject.walkObject(obj, ()=>'');
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_helpers_walkObject = require("./helpers/walkObject.cjs");
|
|
3
|
+
let deep_object_diff = require("deep-object-diff");
|
|
4
|
+
//#region src/validateContract.ts
|
|
5
|
+
const normaliseObject = (obj) => require_helpers_walkObject.walkObject(obj, () => "");
|
|
7
6
|
function validateContract(contract, tokens) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
const theDiff = (0, deep_object_diff.diff)(normaliseObject(contract), normaliseObject(tokens));
|
|
8
|
+
const valid = Object.keys(theDiff).length === 0;
|
|
9
|
+
return {
|
|
10
|
+
valid,
|
|
11
|
+
diffString: valid ? "" : renderDiff(contract, theDiff)
|
|
12
|
+
};
|
|
14
13
|
}
|
|
15
14
|
function diffLine(value, nesting, type) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
if (type === '+') {
|
|
25
|
-
return `\x1b[32m${line}\x1b[0m`; // Green for '+' type
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return line;
|
|
15
|
+
const whitespace = [...Array(nesting).keys()].map(() => " ").join("");
|
|
16
|
+
const line = `${type ? type : " "}${whitespace}${value}`;
|
|
17
|
+
if (process.env.NODE_ENV !== "test") {
|
|
18
|
+
if (type === "-") return `\x1b[31m${line}\x1b[0m`;
|
|
19
|
+
if (type === "+") return `\x1b[32m${line}\x1b[0m`;
|
|
20
|
+
}
|
|
21
|
+
return line;
|
|
29
22
|
}
|
|
30
23
|
function renderDiff(orig, diff, nesting = 0) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
lines.push(diffLine(`${key}: ...,`, innerNesting, '-'));
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (nesting === 0) {
|
|
50
|
-
lines.push(diffLine('}', 0));
|
|
51
|
-
}
|
|
52
|
-
return lines.join('\n');
|
|
24
|
+
const lines = [];
|
|
25
|
+
if (nesting === 0) lines.push(diffLine("{", 0));
|
|
26
|
+
const innerNesting = nesting + 1;
|
|
27
|
+
const keys = Object.keys(diff).sort();
|
|
28
|
+
for (const key of keys) {
|
|
29
|
+
const value = diff[key];
|
|
30
|
+
if (!(key in orig)) lines.push(diffLine(`${key}: ...,`, innerNesting, "+"));
|
|
31
|
+
else if (typeof value === "object") {
|
|
32
|
+
lines.push(diffLine(`${key}: {`, innerNesting));
|
|
33
|
+
lines.push(renderDiff(orig[key], diff[key], innerNesting));
|
|
34
|
+
lines.push(diffLine("}", innerNesting));
|
|
35
|
+
} else lines.push(diffLine(`${key}: ...,`, innerNesting, "-"));
|
|
36
|
+
}
|
|
37
|
+
if (nesting === 0) lines.push(diffLine("}", 0));
|
|
38
|
+
return lines.join("\n");
|
|
53
39
|
}
|
|
54
|
-
|
|
40
|
+
//#endregion
|
|
55
41
|
exports.validateContract = validateContract;
|
package/validateContract.mjs
CHANGED
|
@@ -1,53 +1,43 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import "node:path";
|
|
2
|
+
import "node:url";
|
|
3
|
+
import.meta.url;
|
|
4
|
+
import { walkObject } from "./helpers/walkObject.mjs";
|
|
5
|
+
import { diff } from "deep-object-diff";
|
|
6
|
+
//#region src/validateContract.ts
|
|
7
|
+
const normaliseObject = (obj) => walkObject(obj, () => "");
|
|
5
8
|
function validateContract(contract, tokens) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const theDiff = diff(normaliseObject(contract), normaliseObject(tokens));
|
|
10
|
+
const valid = Object.keys(theDiff).length === 0;
|
|
11
|
+
return {
|
|
12
|
+
valid,
|
|
13
|
+
diffString: valid ? "" : renderDiff(contract, theDiff)
|
|
14
|
+
};
|
|
12
15
|
}
|
|
13
16
|
function diffLine(value, nesting, type) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
if (type === '+') {
|
|
23
|
-
return `\x1b[32m${line}\x1b[0m`; // Green for '+' type
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return line;
|
|
17
|
+
const whitespace = [...Array(nesting).keys()].map(() => " ").join("");
|
|
18
|
+
const line = `${type ? type : " "}${whitespace}${value}`;
|
|
19
|
+
if (process.env.NODE_ENV !== "test") {
|
|
20
|
+
if (type === "-") return `\x1b[31m${line}\x1b[0m`;
|
|
21
|
+
if (type === "+") return `\x1b[32m${line}\x1b[0m`;
|
|
22
|
+
}
|
|
23
|
+
return line;
|
|
27
24
|
}
|
|
28
25
|
function renderDiff(orig, diff, nesting = 0) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
lines.push(diffLine(`${key}: ...,`, innerNesting, '-'));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (nesting === 0) {
|
|
48
|
-
lines.push(diffLine('}', 0));
|
|
49
|
-
}
|
|
50
|
-
return lines.join('\n');
|
|
26
|
+
const lines = [];
|
|
27
|
+
if (nesting === 0) lines.push(diffLine("{", 0));
|
|
28
|
+
const innerNesting = nesting + 1;
|
|
29
|
+
const keys = Object.keys(diff).sort();
|
|
30
|
+
for (const key of keys) {
|
|
31
|
+
const value = diff[key];
|
|
32
|
+
if (!(key in orig)) lines.push(diffLine(`${key}: ...,`, innerNesting, "+"));
|
|
33
|
+
else if (typeof value === "object") {
|
|
34
|
+
lines.push(diffLine(`${key}: {`, innerNesting));
|
|
35
|
+
lines.push(renderDiff(orig[key], diff[key], innerNesting));
|
|
36
|
+
lines.push(diffLine("}", innerNesting));
|
|
37
|
+
} else lines.push(diffLine(`${key}: ...,`, innerNesting, "-"));
|
|
38
|
+
}
|
|
39
|
+
if (nesting === 0) lines.push(diffLine("}", 0));
|
|
40
|
+
return lines.join("\n");
|
|
51
41
|
}
|
|
52
|
-
|
|
42
|
+
//#endregion
|
|
53
43
|
export { validateContract };
|
package/vars.cjs
CHANGED
|
@@ -1,47 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_helpers_walkObject = require("./helpers/walkObject.cjs");
|
|
4
|
+
const require_validateContract = require("./validateContract.cjs");
|
|
5
|
+
let _navita_adapter = require("@navita/adapter");
|
|
6
|
+
let cssesc = require("cssesc");
|
|
7
|
+
cssesc = require_runtime.__toESM(cssesc);
|
|
8
|
+
//#region src/vars.ts
|
|
8
9
|
function createVar(name) {
|
|
9
|
-
|
|
10
|
-
isIdentifier: true
|
|
11
|
-
})}`;
|
|
10
|
+
return `--${(0, cssesc.default)(!name ? (0, _navita_adapter.generateIdentifier)(void 0) : name, { isIdentifier: true })}`;
|
|
12
11
|
}
|
|
13
12
|
function fallbackVar(...values) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
finalValue = value.replace(/\)$/, `, ${finalValue})`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return finalValue;
|
|
13
|
+
let finalValue = "";
|
|
14
|
+
for (let value of values.reverse()) {
|
|
15
|
+
if (/^--/.test(value)) value = `var(${value})`;
|
|
16
|
+
if (finalValue === "") finalValue = String(value);
|
|
17
|
+
else {
|
|
18
|
+
if (typeof value !== "string" || !/^var\(--.*\)$/.test(value)) throw new Error(`Invalid variable name: ${value}`);
|
|
19
|
+
finalValue = value.replace(/\)$/, `, ${finalValue})`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return finalValue;
|
|
29
23
|
}
|
|
30
24
|
function assignVars(varContract, tokens) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
})}`;
|
|
40
|
-
varSetters[cssVarWithoutVar] = String(value);
|
|
41
|
-
});
|
|
42
|
-
return varSetters;
|
|
25
|
+
const varSetters = {};
|
|
26
|
+
const { valid, diffString } = require_validateContract.validateContract(varContract, tokens);
|
|
27
|
+
if (!valid) throw new Error(`Tokens don't match contract.\n${diffString}`);
|
|
28
|
+
require_helpers_walkObject.walkObject(tokens, (value, path) => {
|
|
29
|
+
const cssVarWithoutVar = `--${(0, cssesc.default)(path.join("-").toLowerCase(), { isIdentifier: true })}`;
|
|
30
|
+
varSetters[cssVarWithoutVar] = String(value);
|
|
31
|
+
});
|
|
32
|
+
return varSetters;
|
|
43
33
|
}
|
|
44
|
-
|
|
34
|
+
//#endregion
|
|
45
35
|
exports.assignVars = assignVars;
|
|
46
36
|
exports.createVar = createVar;
|
|
47
37
|
exports.fallbackVar = fallbackVar;
|
package/vars.mjs
CHANGED
|
@@ -1,43 +1,35 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import "node:path";
|
|
2
|
+
import "node:url";
|
|
3
|
+
import.meta.url;
|
|
4
|
+
import { walkObject } from "./helpers/walkObject.mjs";
|
|
5
|
+
import { validateContract } from "./validateContract.mjs";
|
|
6
|
+
import { generateIdentifier } from "@navita/adapter";
|
|
7
|
+
import cssesc from "cssesc";
|
|
8
|
+
//#region src/vars.ts
|
|
6
9
|
function createVar(name) {
|
|
7
|
-
|
|
8
|
-
isIdentifier: true
|
|
9
|
-
})}`;
|
|
10
|
+
return `--${cssesc(!name ? generateIdentifier(void 0) : name, { isIdentifier: true })}`;
|
|
10
11
|
}
|
|
11
12
|
function fallbackVar(...values) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
finalValue = value.replace(/\)$/, `, ${finalValue})`);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return finalValue;
|
|
13
|
+
let finalValue = "";
|
|
14
|
+
for (let value of values.reverse()) {
|
|
15
|
+
if (/^--/.test(value)) value = `var(${value})`;
|
|
16
|
+
if (finalValue === "") finalValue = String(value);
|
|
17
|
+
else {
|
|
18
|
+
if (typeof value !== "string" || !/^var\(--.*\)$/.test(value)) throw new Error(`Invalid variable name: ${value}`);
|
|
19
|
+
finalValue = value.replace(/\)$/, `, ${finalValue})`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return finalValue;
|
|
27
23
|
}
|
|
28
24
|
function assignVars(varContract, tokens) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
})}`;
|
|
38
|
-
varSetters[cssVarWithoutVar] = String(value);
|
|
39
|
-
});
|
|
40
|
-
return varSetters;
|
|
25
|
+
const varSetters = {};
|
|
26
|
+
const { valid, diffString } = validateContract(varContract, tokens);
|
|
27
|
+
if (!valid) throw new Error(`Tokens don't match contract.\n${diffString}`);
|
|
28
|
+
walkObject(tokens, (value, path) => {
|
|
29
|
+
const cssVarWithoutVar = `--${cssesc(path.join("-").toLowerCase(), { isIdentifier: true })}`;
|
|
30
|
+
varSetters[cssVarWithoutVar] = String(value);
|
|
31
|
+
});
|
|
32
|
+
return varSetters;
|
|
41
33
|
}
|
|
42
|
-
|
|
34
|
+
//#endregion
|
|
43
35
|
export { assignVars, createVar, fallbackVar };
|