@cyclone-ui/theme-builder 0.0.20 → 0.0.22
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/build.cjs +1 -0
- package/dist/build.d.cts +37 -0
- package/dist/build.d.cts.map +1 -0
- package/dist/build.d.mts +37 -0
- package/dist/build.d.mts.map +1 -0
- package/dist/build.mjs +2 -0
- package/dist/build.mjs.map +1 -0
- package/dist/generate.cjs +14 -2
- package/dist/generate.d.cts +1 -4
- package/dist/generate.d.cts.map +1 -1
- package/dist/generate.d.mts +1 -4
- package/dist/generate.mjs +14 -2
- package/dist/generate.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +1 -1
- package/dist/preprocessor.d.cts +1 -1
- package/dist/preprocessor.d.mts +1 -1
- package/package.json +18 -4
- package/src/build.ts +116 -0
- package/src/generate.ts +25 -64
- package/src/index.ts +1 -0
- package/test/build.spec.ts +33 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog for Cyclone UI - Theme Builder
|
|
4
4
|
|
|
5
|
+
## [0.0.22](https://github.com/storm-software/cyclone-ui/releases/tag/theme-builder%400.0.22) (10/25/2026)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- **nextjs:** Add support for providing tokens as build config ([09ca705a1](https://github.com/storm-software/cyclone-ui/commit/09ca705a1))
|
|
10
|
+
|
|
5
11
|
## [0.0.17](https://github.com/storm-software/cyclone-ui/releases/tag/theme-builder%400.0.17) (10/23/2026)
|
|
6
12
|
|
|
7
13
|
### Documentation
|
package/dist/build.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./preprocessor.cjs"),t=require("./generate.cjs");let n=require("@razorwind/core"),r=require("node:fs/promises"),i=require("node:path");async function a({tokens:a,cwd:o=process.cwd(),outputPath:s=`.cyclone-ui/tamagui.config.ts`}){let c=(0,i.resolve)(o),l=await(0,n.resolveConfig)(c,{mode:`production`});if(typeof a==`object`&&!Array.isArray(a)){let e=(0,i.join)((0,i.dirname)((0,i.resolve)(c,s)),`tokens.json`);await(0,r.mkdir)((0,i.dirname)(e),{recursive:!0}),await(0,r.writeFile)(e,JSON.stringify(a),`utf8`),l.tokensPath=e}else l.tokensPath=a;l.tokens=void 0,l.plugins=[e.default(),...l.plugins.filter(e=>!e.generate&&e.name!==`cyclone-ui:tamagui-preprocessor`),t({outputPath:s,animations:!1,importConfig:`@cyclone-ui/tokens/tamagui-defaults`})];let u=await(0,n.prepareSpec)({cwd:c,options:l});if((0,n.isEmptyTokens)(u.tokens))throw Error(`No design tokens found in ${JSON.stringify(l.tokensPath)}.`);return await(0,n.writeGeneratedDocuments)(await(0,n.generatePluginDocuments)(u,l),c),(0,i.resolve)(c,s)}exports.buildTamaguiConfig=a;
|
package/dist/build.d.cts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
interface BuildTamaguiConfigOptions {
|
|
2
|
+
/**
|
|
3
|
+
* The design tokens: a DTCG token object, or token file path(s) or globs
|
|
4
|
+
* relative to `cwd`. Theme-named files (`light.tokens.json`,
|
|
5
|
+
* `dark.tokens.json`, …) become the `light` / `dark` themes.
|
|
6
|
+
*/
|
|
7
|
+
tokens: string | string[] | Record<string, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* The project root.
|
|
10
|
+
*
|
|
11
|
+
* @defaultValue `process.cwd()`
|
|
12
|
+
*/
|
|
13
|
+
cwd?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The generated config file, relative to `cwd`.
|
|
16
|
+
*
|
|
17
|
+
* @defaultValue `".cyclone-ui/tamagui.config.ts"`
|
|
18
|
+
*/
|
|
19
|
+
outputPath?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Generate a Tamagui config from design tokens, the same way
|
|
23
|
+
* `@cyclone-ui/tokens` builds its own.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* Tokens go through the Cyclone UI preprocessor (state variants, focus rings)
|
|
27
|
+
* and the Cyclone Tamagui generator. The config imports its media, shorthands,
|
|
28
|
+
* settings and animations from `@cyclone-ui/tokens/tamagui-defaults`, so the
|
|
29
|
+
* app only needs `@cyclone-ui/tokens` and `@tamagui/core` to load it. A
|
|
30
|
+
* `razorwind.config.ts` in `cwd` still applies (fonts, extract plugins), but
|
|
31
|
+
* its generators don't run.
|
|
32
|
+
*
|
|
33
|
+
* @returns The absolute path of the generated config.
|
|
34
|
+
*/
|
|
35
|
+
declare function buildTamaguiConfig({ tokens, cwd, outputPath }: BuildTamaguiConfigOptions): Promise<string>;
|
|
36
|
+
export { BuildTamaguiConfigOptions, buildTamaguiConfig };
|
|
37
|
+
//# sourceMappingURL=build.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.cts","names":[],"sources":["../src/build.ts"],"mappings":"A,UA8BiB;;;;;;EAMf,4BAA4B;;;;;;EAO5B;;;;;;EAOA;;;;;;;;;;;;;;;;iBAiBoB,qBACpB,QACA,KACA,cACC,4BAA4B"}
|
package/dist/build.d.mts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
interface BuildTamaguiConfigOptions {
|
|
2
|
+
/**
|
|
3
|
+
* The design tokens: a DTCG token object, or token file path(s) or globs
|
|
4
|
+
* relative to `cwd`. Theme-named files (`light.tokens.json`,
|
|
5
|
+
* `dark.tokens.json`, …) become the `light` / `dark` themes.
|
|
6
|
+
*/
|
|
7
|
+
tokens: string | string[] | Record<string, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* The project root.
|
|
10
|
+
*
|
|
11
|
+
* @defaultValue `process.cwd()`
|
|
12
|
+
*/
|
|
13
|
+
cwd?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The generated config file, relative to `cwd`.
|
|
16
|
+
*
|
|
17
|
+
* @defaultValue `".cyclone-ui/tamagui.config.ts"`
|
|
18
|
+
*/
|
|
19
|
+
outputPath?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Generate a Tamagui config from design tokens, the same way
|
|
23
|
+
* `@cyclone-ui/tokens` builds its own.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* Tokens go through the Cyclone UI preprocessor (state variants, focus rings)
|
|
27
|
+
* and the Cyclone Tamagui generator. The config imports its media, shorthands,
|
|
28
|
+
* settings and animations from `@cyclone-ui/tokens/tamagui-defaults`, so the
|
|
29
|
+
* app only needs `@cyclone-ui/tokens` and `@tamagui/core` to load it. A
|
|
30
|
+
* `razorwind.config.ts` in `cwd` still applies (fonts, extract plugins), but
|
|
31
|
+
* its generators don't run.
|
|
32
|
+
*
|
|
33
|
+
* @returns The absolute path of the generated config.
|
|
34
|
+
*/
|
|
35
|
+
declare function buildTamaguiConfig({ tokens, cwd, outputPath }: BuildTamaguiConfigOptions): Promise<string>;
|
|
36
|
+
export { BuildTamaguiConfigOptions, buildTamaguiConfig };
|
|
37
|
+
//# sourceMappingURL=build.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.mts","names":[],"sources":["../src/build.ts"],"mappings":""}
|
package/dist/build.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"./preprocessor.mjs";import t from"./generate.mjs";import{generatePluginDocuments as n,isEmptyTokens as r,prepareSpec as i,resolveConfig as a,writeGeneratedDocuments as o}from"@razorwind/core";import{mkdir as s,writeFile as c}from"node:fs/promises";import{dirname as l,join as u,resolve as d}from"node:path";async function f({tokens:f,cwd:p=process.cwd(),outputPath:m=`.cyclone-ui/tamagui.config.ts`}){let h=d(p),g=await a(h,{mode:`production`});if(typeof f==`object`&&!Array.isArray(f)){let e=u(l(d(h,m)),`tokens.json`);await s(l(e),{recursive:!0}),await c(e,JSON.stringify(f),`utf8`),g.tokensPath=e}else g.tokensPath=f;g.tokens=void 0,g.plugins=[e(),...g.plugins.filter(e=>!e.generate&&e.name!==`cyclone-ui:tamagui-preprocessor`),t({outputPath:m,animations:!1,importConfig:`@cyclone-ui/tokens/tamagui-defaults`})];let _=await i({cwd:h,options:g});if(r(_.tokens))throw Error(`No design tokens found in ${JSON.stringify(g.tokensPath)}.`);return await o(await n(_,g),h),d(h,m)}export{f as buildTamaguiConfig};
|
|
2
|
+
//# sourceMappingURL=build.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.mjs","names":["preprocessor","generate","preprocessor_default","generate_default","buildTamaguiConfig","root","resolve","cwd","config","resolveConfig","tokens","tokensFile","join","dirname","outputPath","mkdir","writeFile","plugin","spec","prepareSpec","isEmptyTokens","writeGeneratedDocuments","generatePluginDocuments"],"sources":[],"mappings":""}
|
package/dist/generate.cjs
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("@razorwind/core/plugin"),l=require("@razorwind/tamagui/generate");l=s(l);
|
|
2
|
-
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("@razorwind/core/plugin"),l=require("@razorwind/tamagui/generate");l=s(l);var u=(0,c.definePlugin)((e={})=>{let t={animations:`motion`,defaultFont:`body`,target:`v3`,tamaguiModule:`@tamagui/core`,...e},n=(0,l.default)(t),r=n.generate,i=e=>{for(let t of Object.values(e??{}))for(let e of t?.chunks??[])typeof e.content==`string`&&e.content.includes(`createTamagui(`)&&(e.content+=`
|
|
2
|
+
for (const scheme of ["light", "dark"]) {
|
|
3
|
+
const all = config.themes as Record<string, Record<string, unknown>>;
|
|
4
|
+
const root = all[scheme];
|
|
5
|
+
const base = all[\`\${scheme}_base\`];
|
|
6
|
+
if (root && base) {
|
|
7
|
+
for (const key of Object.keys(base)) {
|
|
8
|
+
if (!(key in root)) {
|
|
9
|
+
root[key] = base[key];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
`);return e};return{...n,name:`cyclone-ui:tamagui-generate`,generate:async(...[e,t])=>{if(!r||!e.fonts)return i(await r?.(e,t)??{});let n=Object.fromEntries(Object.entries(e.fonts).map(([e,t])=>t.source!==`local`||!t.files?[e,t]:[e,{...t,files:t.files.filter(e=>typeof e.weight!=`string`||/^\d+(?:\.\d+)?$/u.test(e.weight.trim()))}]));return i(await r({...e,fonts:n},t))}}});module.exports=u;
|
package/dist/generate.d.cts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { TamaguiPluginOptions } from "@razorwind/tamagui";
|
|
2
|
-
|
|
3
|
-
tamaguiModule?: string;
|
|
4
|
-
};
|
|
5
|
-
declare const _default: (options?: GenerateOptions | undefined) => import("@razorwind/core/plugin").Plugin;
|
|
2
|
+
declare const _default: (options?: TamaguiPluginOptions | undefined) => import("@razorwind/core").Plugin;
|
|
6
3
|
export = _default;
|
|
7
4
|
//# sourceMappingURL=generate.d.cts.map
|
package/dist/generate.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.cts","names":[],"sources":["../src/generate.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate.d.cts","names":[],"sources":["../src/generate.ts"],"mappings":""}
|
package/dist/generate.d.mts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { TamaguiPluginOptions } from "@razorwind/tamagui";
|
|
2
|
-
|
|
3
|
-
tamaguiModule?: string;
|
|
4
|
-
};
|
|
5
|
-
declare const _default: (options?: GenerateOptions | undefined) => import("@razorwind/core/plugin").Plugin;
|
|
2
|
+
declare const _default: (options?: TamaguiPluginOptions | undefined) => import("@razorwind/core").Plugin;
|
|
6
3
|
export { _default as default };
|
|
7
4
|
//# sourceMappingURL=generate.d.mts.map
|
package/dist/generate.mjs
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
import{definePlugin as e}from"@razorwind/core/plugin";import t from"@razorwind/tamagui/generate";
|
|
2
|
-
|
|
1
|
+
import{definePlugin as e}from"@razorwind/core/plugin";import t from"@razorwind/tamagui/generate";var n=e((e={})=>{let n={animations:`motion`,defaultFont:`body`,target:`v3`,tamaguiModule:`@tamagui/core`,...e},r=t(n),i=r.generate,a=e=>{for(let t of Object.values(e??{}))for(let e of t?.chunks??[])typeof e.content==`string`&&e.content.includes(`createTamagui(`)&&(e.content+=`
|
|
2
|
+
for (const scheme of ["light", "dark"]) {
|
|
3
|
+
const all = config.themes as Record<string, Record<string, unknown>>;
|
|
4
|
+
const root = all[scheme];
|
|
5
|
+
const base = all[\`\${scheme}_base\`];
|
|
6
|
+
if (root && base) {
|
|
7
|
+
for (const key of Object.keys(base)) {
|
|
8
|
+
if (!(key in root)) {
|
|
9
|
+
root[key] = base[key];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
`);return e};return{...r,name:`cyclone-ui:tamagui-generate`,generate:async(...[e,t])=>{if(!i||!e.fonts)return a(await i?.(e,t)??{});let n=Object.fromEntries(Object.entries(e.fonts).map(([e,t])=>t.source!==`local`||!t.files?[e,t]:[e,{...t,files:t.files.filter(e=>typeof e.weight!=`string`||/^\d+(?:\.\d+)?$/u.test(e.weight.trim()))}]));return a(await i({...e,fonts:n},t))}}});export{n as default};
|
|
3
15
|
//# sourceMappingURL=generate.mjs.map
|
package/dist/generate.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.mjs","names":["tamagui","
|
|
1
|
+
{"version":3,"file":"generate.mjs","names":["tamagui","generate_default","definePlugin","resolvedOptions","options","tamaguiPlugin","generateTamagui","mirrorBaseThemes","document","documents","chunk","spec","config","fonts","name","font","file"],"sources":[],"mappings":""}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./preprocessor.cjs"),t=require("./generate.cjs");exports.generate=t,exports.preprocessor=e.default;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./preprocessor.cjs"),t=require("./generate.cjs"),n=require("./build.cjs");exports.buildTamaguiConfig=n.buildTamaguiConfig,exports.generate=t,exports.preprocessor=e.default;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BuildTamaguiConfigOptions, buildTamaguiConfig } from "./build.cjs";
|
|
1
2
|
import _default from "./generate.cjs";
|
|
2
3
|
import _default$1 from "./preprocessor.cjs";
|
|
3
|
-
export { _default as generate, _default$1 as preprocessor };
|
|
4
|
+
export { BuildTamaguiConfigOptions, buildTamaguiConfig, _default as generate, _default$1 as preprocessor };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BuildTamaguiConfigOptions, buildTamaguiConfig } from "./build.mjs";
|
|
1
2
|
import _default from "./generate.mjs";
|
|
2
3
|
import _default$1 from "./preprocessor.mjs";
|
|
3
|
-
export { _default as generate, _default$1 as preprocessor };
|
|
4
|
+
export { BuildTamaguiConfigOptions, buildTamaguiConfig, _default as generate, _default$1 as preprocessor };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"./preprocessor.mjs";import t from"./generate.mjs";export{t as generate,e as preprocessor};
|
|
1
|
+
import e from"./preprocessor.mjs";import t from"./generate.mjs";import{buildTamaguiConfig as n}from"./build.mjs";export{n as buildTamaguiConfig,t as generate,e as preprocessor};
|
package/dist/preprocessor.d.cts
CHANGED
|
@@ -22,6 +22,6 @@ import { PreprocessedTokens } from "style-dictionary/types";
|
|
|
22
22
|
* Finally, focus rings are generated for each theme color group.
|
|
23
23
|
*/
|
|
24
24
|
declare function tamaguiPreprocessor(dictionary: PreprocessedTokens): PreprocessedTokens;
|
|
25
|
-
declare const _default: (options?: unknown) => import("@razorwind/core
|
|
25
|
+
declare const _default: (options?: unknown) => import("@razorwind/core").Plugin;
|
|
26
26
|
export { _default as default, tamaguiPreprocessor };
|
|
27
27
|
//# sourceMappingURL=preprocessor.d.cts.map
|
package/dist/preprocessor.d.mts
CHANGED
|
@@ -22,6 +22,6 @@ import { PreprocessedTokens } from "style-dictionary/types";
|
|
|
22
22
|
* Finally, focus rings are generated for each theme color group.
|
|
23
23
|
*/
|
|
24
24
|
declare function tamaguiPreprocessor(dictionary: PreprocessedTokens): PreprocessedTokens;
|
|
25
|
-
declare const _default: (options?: unknown) => import("@razorwind/core
|
|
25
|
+
declare const _default: (options?: unknown) => import("@razorwind/core").Plugin;
|
|
26
26
|
export { _default as default, tamaguiPreprocessor };
|
|
27
27
|
//# sourceMappingURL=preprocessor.d.mts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyclone-ui/theme-builder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -26,6 +26,20 @@
|
|
|
26
26
|
"default": "./dist/index.mjs"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
|
+
"./build": {
|
|
30
|
+
"require": {
|
|
31
|
+
"types": "./dist/build.d.cts",
|
|
32
|
+
"default": "./dist/build.cjs"
|
|
33
|
+
},
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/build.d.mts",
|
|
36
|
+
"default": "./dist/build.mjs"
|
|
37
|
+
},
|
|
38
|
+
"default": {
|
|
39
|
+
"types": "./dist/build.d.mts",
|
|
40
|
+
"default": "./dist/build.mjs"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
29
43
|
"./generate": {
|
|
30
44
|
"require": {
|
|
31
45
|
"types": "./dist/generate.d.cts",
|
|
@@ -60,9 +74,9 @@
|
|
|
60
74
|
"module": "./dist/index.mjs",
|
|
61
75
|
"types": "./dist/index.d.cts",
|
|
62
76
|
"dependencies": {
|
|
63
|
-
"@razorwind/core": "^0.0.
|
|
64
|
-
"@razorwind/style-dictionary": "^0.0.
|
|
65
|
-
"@razorwind/tamagui": "^0.0.
|
|
77
|
+
"@razorwind/core": "^0.0.110",
|
|
78
|
+
"@razorwind/style-dictionary": "^0.0.96",
|
|
79
|
+
"@razorwind/tamagui": "^0.0.116",
|
|
66
80
|
"style-dictionary": "^5.7.0"
|
|
67
81
|
},
|
|
68
82
|
"devDependencies": {
|
package/src/build.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/* -------------------------------------------------------------------
|
|
2
|
+
|
|
3
|
+
🗲 Storm Software - Cyclone UI
|
|
4
|
+
|
|
5
|
+
This code was released as part of the Cyclone UI project. Cyclone UI
|
|
6
|
+
is maintained by Storm Software under the Apache-2.0 license, and is
|
|
7
|
+
free for commercial and private use. For more information, please visit
|
|
8
|
+
our licensing page at https://stormsoftware.com/licenses/projects/cyclone-ui.
|
|
9
|
+
|
|
10
|
+
Website: https://stormsoftware.com
|
|
11
|
+
Repository: https://github.com/storm-software/cyclone-ui
|
|
12
|
+
Documentation: https://docs.stormsoftware.com/projects/cyclone-ui
|
|
13
|
+
Contact: https://stormsoftware.com/contact
|
|
14
|
+
|
|
15
|
+
SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
|
|
17
|
+
------------------------------------------------------------------- */
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
generatePluginDocuments,
|
|
21
|
+
isEmptyTokens,
|
|
22
|
+
prepareSpec,
|
|
23
|
+
resolveConfig,
|
|
24
|
+
writeGeneratedDocuments
|
|
25
|
+
} from "@razorwind/core";
|
|
26
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
27
|
+
import { dirname, join, resolve } from "node:path";
|
|
28
|
+
import generate from "./generate";
|
|
29
|
+
import preprocessor from "./preprocessor";
|
|
30
|
+
|
|
31
|
+
export interface BuildTamaguiConfigOptions {
|
|
32
|
+
/**
|
|
33
|
+
* The design tokens: a DTCG token object, or token file path(s) or globs
|
|
34
|
+
* relative to `cwd`. Theme-named files (`light.tokens.json`,
|
|
35
|
+
* `dark.tokens.json`, …) become the `light` / `dark` themes.
|
|
36
|
+
*/
|
|
37
|
+
tokens: string | string[] | Record<string, unknown>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The project root.
|
|
41
|
+
*
|
|
42
|
+
* @defaultValue `process.cwd()`
|
|
43
|
+
*/
|
|
44
|
+
cwd?: string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The generated config file, relative to `cwd`.
|
|
48
|
+
*
|
|
49
|
+
* @defaultValue `".cyclone-ui/tamagui.config.ts"`
|
|
50
|
+
*/
|
|
51
|
+
outputPath?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Generate a Tamagui config from design tokens, the same way
|
|
56
|
+
* `@cyclone-ui/tokens` builds its own.
|
|
57
|
+
*
|
|
58
|
+
* @remarks
|
|
59
|
+
* Tokens go through the Cyclone UI preprocessor (state variants, focus rings)
|
|
60
|
+
* and the Cyclone Tamagui generator. The config imports its media, shorthands,
|
|
61
|
+
* settings and animations from `@cyclone-ui/tokens/tamagui-defaults`, so the
|
|
62
|
+
* app only needs `@cyclone-ui/tokens` and `@tamagui/core` to load it. A
|
|
63
|
+
* `razorwind.config.ts` in `cwd` still applies (fonts, extract plugins), but
|
|
64
|
+
* its generators don't run.
|
|
65
|
+
*
|
|
66
|
+
* @returns The absolute path of the generated config.
|
|
67
|
+
*/
|
|
68
|
+
export async function buildTamaguiConfig({
|
|
69
|
+
tokens,
|
|
70
|
+
cwd = process.cwd(),
|
|
71
|
+
outputPath = ".cyclone-ui/tamagui.config.ts"
|
|
72
|
+
}: BuildTamaguiConfigOptions): Promise<string> {
|
|
73
|
+
const root = resolve(cwd);
|
|
74
|
+
const config = await resolveConfig(root, { mode: "production" });
|
|
75
|
+
|
|
76
|
+
// Razorwind lets config-file paths win over passed options, so override
|
|
77
|
+
// afterwards. Inline tokens are written to a file because the preprocessor
|
|
78
|
+
// only runs while Razorwind loads token files.
|
|
79
|
+
if (typeof tokens === "object" && !Array.isArray(tokens)) {
|
|
80
|
+
const tokensFile = join(dirname(resolve(root, outputPath)), "tokens.json");
|
|
81
|
+
await mkdir(dirname(tokensFile), { recursive: true });
|
|
82
|
+
await writeFile(tokensFile, JSON.stringify(tokens), "utf8");
|
|
83
|
+
config.tokensPath = tokensFile;
|
|
84
|
+
} else {
|
|
85
|
+
config.tokensPath = tokens;
|
|
86
|
+
}
|
|
87
|
+
config.tokens = undefined;
|
|
88
|
+
config.plugins = [
|
|
89
|
+
preprocessor(),
|
|
90
|
+
...config.plugins.filter(
|
|
91
|
+
plugin =>
|
|
92
|
+
!plugin.generate && plugin.name !== "cyclone-ui:tamagui-preprocessor"
|
|
93
|
+
),
|
|
94
|
+
generate({
|
|
95
|
+
outputPath,
|
|
96
|
+
animations: false,
|
|
97
|
+
importConfig: "@cyclone-ui/tokens/tamagui-defaults"
|
|
98
|
+
})
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
const spec = await prepareSpec({ cwd: root, options: config } as Parameters<
|
|
102
|
+
typeof prepareSpec
|
|
103
|
+
>[0]);
|
|
104
|
+
if (isEmptyTokens(spec.tokens)) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
`No design tokens found in ${JSON.stringify(config.tokensPath)}.`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
await writeGeneratedDocuments(
|
|
111
|
+
await generatePluginDocuments(spec, config),
|
|
112
|
+
root
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
return resolve(root, outputPath);
|
|
116
|
+
}
|
package/src/generate.ts
CHANGED
|
@@ -20,65 +20,28 @@ import { definePlugin } from "@razorwind/core/plugin";
|
|
|
20
20
|
import type { TamaguiPluginOptions } from "@razorwind/tamagui";
|
|
21
21
|
import tamagui from "@razorwind/tamagui/generate";
|
|
22
22
|
|
|
23
|
-
//
|
|
24
|
-
// `
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
// the
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const parseScale = (body: string): Record<string, number> =>
|
|
38
|
-
Object.fromEntries(
|
|
39
|
-
[...body.matchAll(/^\s*"?([\w-]+)"?: ([\d.]+),?$/gmu)].map(
|
|
40
|
-
([, key, value]) => [key, Number(value)]
|
|
41
|
-
)
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
/** Scales a ratio line height (e.g. `1.125`) to px for every font size step. */
|
|
45
|
-
const scaleRatioLineHeights = (content: string) =>
|
|
46
|
-
content.replaceAll(
|
|
47
|
-
/(\n {2}size: \{\n)([^}]*)(\n {2}\},\n {2}lineHeight: \{\n)([^}]*)(\n {2}\})/gu,
|
|
48
|
-
(match, open, sizeBody, middle, lineHeightBody, close) => {
|
|
49
|
-
const sizes = parseScale(sizeBody);
|
|
50
|
-
const lineHeights = parseScale(lineHeightBody);
|
|
51
|
-
const ratio = lineHeights.true ?? Object.values(lineHeights)[0];
|
|
52
|
-
if (ratio == null || ratio <= 0 || ratio > 4) {
|
|
53
|
-
return match;
|
|
23
|
+
// Tamagui v3 resolves `styled()` base and variant values against the first
|
|
24
|
+
// theme (`light`), but the root `light` / `dark` themes only carry the keys
|
|
25
|
+
// every child theme shares, so keys the `base` child adds (`accent`, `ring*`,
|
|
26
|
+
// …) don't resolve and the declaration is dropped. Mirror them onto each root
|
|
27
|
+
// theme so they resolve to CSS variables the active child theme supplies.
|
|
28
|
+
const MIRROR_BASE_THEMES = `
|
|
29
|
+
for (const scheme of ["light", "dark"]) {
|
|
30
|
+
const all = config.themes as Record<string, Record<string, unknown>>;
|
|
31
|
+
const root = all[scheme];
|
|
32
|
+
const base = all[\`\${scheme}_base\`];
|
|
33
|
+
if (root && base) {
|
|
34
|
+
for (const key of Object.keys(base)) {
|
|
35
|
+
if (!(key in root)) {
|
|
36
|
+
root[key] = base[key];
|
|
54
37
|
}
|
|
55
|
-
|
|
56
|
-
const round = (value: number) => Math.round(value * 1000) / 1000;
|
|
57
|
-
const scale = Object.fromEntries(
|
|
58
|
-
Object.entries(sizes).map(([key, size]) => [key, round(ratio * size)])
|
|
59
|
-
);
|
|
60
|
-
const base = scale.sm ?? Object.values(scale)[0] ?? ratio;
|
|
61
|
-
|
|
62
|
-
return `${open}${sizeBody}${middle}${renderScale({
|
|
63
|
-
...Object.fromEntries(Object.keys(lineHeights).map(key => [key, base])),
|
|
64
|
-
...scale
|
|
65
|
-
})}${close}`;
|
|
66
38
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
content
|
|
71
|
-
.replaceAll('from "tamagui";', `from "${tamaguiModule}";`)
|
|
72
|
-
.replaceAll(
|
|
73
|
-
'declare module "tamagui"',
|
|
74
|
-
`declare module "${tamaguiModule}"`
|
|
75
|
-
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
76
42
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
export default definePlugin((options: GenerateOptions = {}) => {
|
|
81
|
-
const resolvedOptions: GenerateOptions = {
|
|
43
|
+
export default definePlugin((options: TamaguiPluginOptions = {}) => {
|
|
44
|
+
const resolvedOptions: TamaguiPluginOptions = {
|
|
82
45
|
animations: "motion",
|
|
83
46
|
defaultFont: "body",
|
|
84
47
|
target: "v3",
|
|
@@ -88,9 +51,8 @@ export default definePlugin((options: GenerateOptions = {}) => {
|
|
|
88
51
|
};
|
|
89
52
|
const tamaguiPlugin = tamagui(resolvedOptions);
|
|
90
53
|
const generateTamagui = tamaguiPlugin.generate;
|
|
91
|
-
const tamaguiModule = resolvedOptions.tamaguiModule ?? "tamagui";
|
|
92
54
|
|
|
93
|
-
const
|
|
55
|
+
const mirrorBaseThemes = (
|
|
94
56
|
documents: Awaited<ReturnType<NonNullable<typeof generateTamagui>>>
|
|
95
57
|
) => {
|
|
96
58
|
for (const document of Object.values(documents ?? {})) {
|
|
@@ -99,10 +61,7 @@ export default definePlugin((options: GenerateOptions = {}) => {
|
|
|
99
61
|
typeof chunk.content === "string" &&
|
|
100
62
|
chunk.content.includes("createTamagui(")
|
|
101
63
|
) {
|
|
102
|
-
chunk.content
|
|
103
|
-
scaleRatioLineHeights(chunk.content),
|
|
104
|
-
tamaguiModule
|
|
105
|
-
);
|
|
64
|
+
chunk.content += MIRROR_BASE_THEMES;
|
|
106
65
|
}
|
|
107
66
|
}
|
|
108
67
|
}
|
|
@@ -117,7 +76,7 @@ export default definePlugin((options: GenerateOptions = {}) => {
|
|
|
117
76
|
...[spec, config]: Parameters<NonNullable<typeof generateTamagui>>
|
|
118
77
|
) => {
|
|
119
78
|
if (!generateTamagui || !spec.fonts) {
|
|
120
|
-
return
|
|
79
|
+
return mirrorBaseThemes((await generateTamagui?.(spec, config)) ?? {});
|
|
121
80
|
}
|
|
122
81
|
|
|
123
82
|
const fonts = Object.fromEntries(
|
|
@@ -140,7 +99,9 @@ export default definePlugin((options: GenerateOptions = {}) => {
|
|
|
140
99
|
})
|
|
141
100
|
) as typeof spec.fonts;
|
|
142
101
|
|
|
143
|
-
return
|
|
102
|
+
return mirrorBaseThemes(
|
|
103
|
+
await generateTamagui({ ...spec, fonts }, config)
|
|
104
|
+
);
|
|
144
105
|
}
|
|
145
106
|
};
|
|
146
107
|
});
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { afterAll, describe, expect, it } from "vitest";
|
|
5
|
+
|
|
6
|
+
import { buildTamaguiConfig } from "../src/build";
|
|
7
|
+
|
|
8
|
+
const cwd = await mkdtemp(join(tmpdir(), "cyclone-ui-build-"));
|
|
9
|
+
afterAll(async () => rm(cwd, { recursive: true, force: true }));
|
|
10
|
+
|
|
11
|
+
describe("buildTamaguiConfig", () => {
|
|
12
|
+
it("builds split light and dark themes from token files", async () => {
|
|
13
|
+
const file = await buildTamaguiConfig({
|
|
14
|
+
cwd,
|
|
15
|
+
tokens: resolve(import.meta.dirname, "../../tokens/src/tokens/**/*.json")
|
|
16
|
+
});
|
|
17
|
+
const source = await readFile(file, "utf8");
|
|
18
|
+
const canvas = (scheme: string) =>
|
|
19
|
+
new RegExp(`\\n ${scheme}: \\{\\n canvas: ([^,]+),`, "u").exec(
|
|
20
|
+
source
|
|
21
|
+
)?.[1];
|
|
22
|
+
|
|
23
|
+
expect(file).toBe(join(cwd, ".cyclone-ui/tamagui.config.ts"));
|
|
24
|
+
expect(source).toContain(
|
|
25
|
+
'import userConfig from "@cyclone-ui/tokens/tamagui-defaults";'
|
|
26
|
+
);
|
|
27
|
+
expect(source).not.toContain("@tamagui/config");
|
|
28
|
+
expect(canvas("light")).toBeDefined();
|
|
29
|
+
expect(canvas("dark")).toBeDefined();
|
|
30
|
+
expect(canvas("light")).not.toBe(canvas("dark"));
|
|
31
|
+
expect(source).toContain("root[key] = base[key];");
|
|
32
|
+
});
|
|
33
|
+
});
|