@terrazzo/plugin-vanilla-extract 0.0.1

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 ADDED
@@ -0,0 +1,5 @@
1
+ # @terrazzo/plugin-vanilla-extract
2
+
3
+ ## 0.0.1
4
+
5
+ Initial release
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Drew Powers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # ⛋ @terrazzo/plugin-vanilla-extract
2
+
3
+ Generate [Vanilla Extract](https://vanilla-extract.style) CSS themes from DTCG tokens.
4
+
5
+ ## Setup
6
+
7
+ Requires [Node.js 20 or later](https://nodejs.org). With that installed, run:
8
+
9
+ ```sh
10
+ npm i -D @terrazzo/cli @terrazzo/plugin-css @terrazzo/plugin-vanilla-extract
11
+ ```
12
+
13
+ Add a `terrazzo.config.js` to the root of your project with:
14
+
15
+ ```ts
16
+ import { defineConfig } from "@terrazzo/cli";
17
+ import css from "@terrazzo/plugin-css";
18
+ import vanillaExtract from "@terrazzo/plugin-vanilla-extract";
19
+
20
+ export default defineConfig({
21
+ plugins: [
22
+ css({
23
+ // Optional: control the final CSS variable names
24
+ variableName: (id) => id.replace(/\./g, "-"),
25
+ // Optional: pass `skipBuild: true` to not generate a .css file if only using Vanilla Extract.
26
+ skipBuild: false,
27
+ }),
28
+
29
+ vanillaExtract({
30
+ filename: "themes.css.ts",
31
+
32
+ // generate createTheme()
33
+ themes: [
34
+ { name: "light", mode: "light" },
35
+ { name: "dark", mode: "dark" },
36
+ ],
37
+
38
+ // generate createGlobalTheme()
39
+ globalThemes: [
40
+ { selector: "@media (prefers-color-scheme: light)", mode: "light" },
41
+ { selector: "@media (prefers-color-scheme: dark)", mode: "dark" },
42
+ ],
43
+ }),
44
+ ],
45
+ });
46
+ ```
47
+
48
+ This plugin extends [plugin-css](../plugin-css) and always generates [createGlobalThemeContract()](https://vanilla-extract.style/documentation/global-api/create-global-theme-contract/) to match your generated CSS global variable names 1:1. But from there, you can use either locally-scoped ([createThem()](https://vanilla-extract.style/documentation/api/create-theme/)) or globally-scoped ([createGlobalTheme()](https://vanilla-extract.style/documentation/global-api/create-global-theme/)) themes.
49
+
50
+ [View documentation](https://terrazzo.app/docs/integrations/vanilla-extract)
@@ -0,0 +1,96 @@
1
+ import { Plugin, TokenTransformed } from "@terrazzo/parser";
2
+
3
+ //#region src/lib.d.ts
4
+ declare const FORMAT_ID = "vanilla-extract";
5
+ declare const THEME_CONTRACT_VAR = "tzVars";
6
+ interface VanillaExtractPluginOptions {
7
+ /**
8
+ * Filename to generate.
9
+ * @default "theme.css.ts"
10
+ */
11
+ filename?: string;
12
+ /**
13
+ * - true: use global `createGlobalThemeContract()` API
14
+ * - false: use scoped `createThemeContract()` API
15
+ * @default true
16
+ */
17
+ globalThemeContract?: boolean;
18
+ /**
19
+ * Mapping of exported JS variables to token modes. The key MUST be a valid JS identifier.
20
+ * @example
21
+ *
22
+ * ```js
23
+ * themes: {
24
+ * default: { mode: "." }, // "." refers to the default mode, or no mode
25
+ * light: { mode: "light" },
26
+ * dark: { mode: "dark" },
27
+ * }
28
+ * ```
29
+ */
30
+ themes?: Record<string, {
31
+ mode: string | string[];
32
+ }>;
33
+ /**
34
+ * Mapping of exported JS variables to token modes for global themes. The key MUST be a valid JS identifier.
35
+ * @example
36
+ *
37
+ * ```js
38
+ * globalThemes: {
39
+ * default: { selector: ":root", mode: "." }, // "." refers to the default mode, or no mode
40
+ * light: { selector: "[data-color-mode=light]", mode: "light" },
41
+ * dark: { selector: "[data-color-mode=dark]" mode: "dark" },
42
+ * }
43
+ * ```
44
+ */
45
+ globalThemes?: Record<string, {
46
+ selector: string;
47
+ mode: string | string[];
48
+ }>;
49
+ /**
50
+ * Change the naming strategy for the createTheme() API’s `[class, vars]` tuple.
51
+ * @default (name) => [`${name}Class`, name]
52
+ */
53
+ themeVarNaming?: (name: string) => [string, string];
54
+ }
55
+ declare const VE: {
56
+ createTheme: string;
57
+ createGlobalTheme: string;
58
+ createThemeContract: string;
59
+ createGlobalThemeContract: string;
60
+ };
61
+ declare function isJSIdent(ident: unknown): boolean;
62
+ /** Generate createThemeContract() or createGlobalThemeContract() */
63
+ declare function generateThemeContract({
64
+ tokens,
65
+ globalThemeContract
66
+ }: {
67
+ tokens: TokenTransformed[];
68
+ globalThemeContract: boolean;
69
+ }): string;
70
+ /** Generate createTheme()/createGlobalTheme() */
71
+ declare function generateTheme({
72
+ name,
73
+ namingPattern,
74
+ tokens,
75
+ selector,
76
+ globalTheme
77
+ }: {
78
+ name: string;
79
+ namingPattern: (name: string) => [string, string];
80
+ tokens: TokenTransformed[];
81
+ selector?: string;
82
+ globalTheme?: boolean;
83
+ }): string;
84
+ /** Encode an alias to a Vanilla Extract token inside a JSON array */
85
+ declare function serializeValue(value: string | number | boolean, tokens: TokenTransformed[]): string;
86
+ /** Decode all aliases from a JSON string */
87
+ declare function deserializeAllValues(json: string): string;
88
+ //# sourceMappingURL=lib.d.ts.map
89
+ //#endregion
90
+ //#region src/index.d.ts
91
+ declare function vanillaExtractPlugin(options: VanillaExtractPluginOptions): Plugin;
92
+ //# sourceMappingURL=index.d.ts.map
93
+
94
+ //#endregion
95
+ export { FORMAT_ID, THEME_CONTRACT_VAR, VE, VanillaExtractPluginOptions, vanillaExtractPlugin as default, deserializeAllValues, generateTheme, generateThemeContract, isJSIdent, serializeValue };
96
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/lib.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;cAGa,SAAA;cACA,kBAAA;AADA,UAGI,2BAAA,CAHK;EACT;AAEb;;;EAwBiB,QAaA,CAAA,EAAA,MAAA;EAAM;AASvB;AAOA;AAQA;;EAAqC,mBACnC,CAAA,EAAA,OAAA;EAAM;;AAGkB;AA0B1B;;;;;;;;AAS0B;EA2CV,MAAA,CAAA,EAvHL,MAuHK,CAAA,MAAc,EAAA;IAyCd,IAAA,EAAA,MAAA,GAAA,MAAoB,EAAA;;;;AClLX;;;;AAEiE;;;;;;iBD6BzE;;;;;;;;;;cASJ;;;;;;iBAOG,SAAA;;iBAQA,qBAAA;;;;UAIN;;;;iBA0BM,aAAA;;;;;;;;;UASN;;;;;iBA2CM,cAAA,2CAAyD;;iBAyCzD,oBAAA;;;;AA3LH,iBCWW,oBAAA,CDXF,OAAA,ECWgC,2BDXhC,CAAA,ECW8D,MDX9D;AACtB"}