@spark-ui/theme-utils 1.1.0 → 1.2.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/CHANGELOG.md CHANGED
@@ -3,6 +3,16 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.2.0](https://github.com/adevinta/spark/compare/@spark-ui/theme-utils@1.1.1...@spark-ui/theme-utils@1.2.0) (2023-02-13)
7
+
8
+ ### Features
9
+
10
+ - **theme-utils:** improve build process for the theme-utils package ([7e53f89](https://github.com/adevinta/spark/commit/7e53f89bb80c7da4f5816b3bdb64b5b9a23d4874)), closes [#219](https://github.com/adevinta/spark/issues/219)
11
+
12
+ ## [1.1.1](https://github.com/adevinta/spark/compare/@spark-ui/theme-utils@1.1.0...@spark-ui/theme-utils@1.1.1) (2023-02-13)
13
+
14
+ **Note:** Version bump only for package @spark-ui/theme-utils
15
+
6
16
  # [1.1.0](https://github.com/adevinta/spark/compare/@spark-ui/theme-utils@0.0.1...@spark-ui/theme-utils@1.1.0) (2023-02-10)
7
17
 
8
18
  ### Features
@@ -0,0 +1,25 @@
1
+ import type { RequireAtLeastOne } from 'type-fest';
2
+ import type { Theme } from './types';
3
+ /**
4
+ * Creates a CSS file containing theme tokens represented as CSS custom properties
5
+ *
6
+ * @param {string} path - The file path where the CSS file will be created.
7
+ * @param {Record<string, Theme>} themeRecord - A record (with a required key of "default") of themes that will be included in the CSS Tokens file.
8
+ *
9
+ * @returns {void}
10
+ *
11
+ * @example
12
+ *
13
+ * const defaultTheme: Theme = { ... }
14
+ * const darkTheme: Theme = { ... }
15
+ * const otherTheme: Theme = { ... }
16
+ *
17
+ * const themes = {
18
+ * default: defaultTheme,
19
+ * dark: darkTheme
20
+ * other: otherTheme
21
+ * }
22
+ *
23
+ * createCSSTokensFile('somePath.css', themes)
24
+ */
25
+ export declare function createCSSTokensFile(path: string, themeRecord: RequireAtLeastOne<Record<string, Theme>, 'default'>): void;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Creates a Tailwind config file that links the [theme options](https://tailwindcss.com/docs/theme#configuration-reference) provided by Tailwind with the CSS custom property values generated using the "createCSSTokensFile" function
3
+ *
4
+ * @param {string} path - The file path where the Tailwind config file will be created.
5
+ *
6
+ * @returns {void}
7
+ *
8
+ * @example
9
+ *
10
+ * createTailwindThemeConfigFile('tailwind.theme.js')
11
+ */
12
+ export declare function createTailwindThemeConfigFile(path: string): void;
@@ -0,0 +1,15 @@
1
+ import { PartialDeep } from 'type-fest';
2
+ import type { Theme } from './types';
3
+ /**
4
+ * Create a custom theme by merging the default theme with a partial custom theme passed as an argument.
5
+ *
6
+ * @param {PartialDeep<Theme>} theme - A partial theme object of type PartialDeep<Theme> which holds the theme values that need to be customized or overridden
7
+ *
8
+ * @returns {Theme}
9
+ *
10
+ * @example
11
+ *
12
+ * const alternativeTheme: PartialDeep<Theme> = { ... }
13
+ * const newTheme = createTheme(alternativeTheme)
14
+ */
15
+ export declare function createTheme(theme?: PartialDeep<Theme>): Theme;
@@ -0,0 +1,2 @@
1
+ import type { Theme } from './types';
2
+ export declare const defaultTheme: Theme;
@@ -0,0 +1,5 @@
1
+ export { createTheme } from './createTheme';
2
+ export { createTailwindThemeConfigFile } from './createTailwindThemeConfigFile';
3
+ export { createCSSTokensFile } from './createCSSTokensFile';
4
+ export { defaultTheme } from './defaultTheme';
5
+ export type { Theme } from './types';
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";var M=Object.defineProperty,P=Object.defineProperties;var z=Object.getOwnPropertyDescriptors;var m=Object.getOwnPropertySymbols;var g=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable;var y=(e,r,t)=>r in e?M(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,$=(e,r)=>{for(var t in r||(r={}))g.call(r,t)&&y(e,t,r[t]);if(m)for(var t of m(r))b.call(r,t)&&y(e,t,r[t]);return e},h=(e,r)=>P(e,z(r));var S=(e,r)=>{var t={};for(var n in e)g.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&m)for(var n of m(e))r.indexOf(n)<0&&b.call(e,n)&&(t[n]=e[n]);return t};Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("deepmerge"),c=require("fs"),j=require("parent-module"),w=require("path"),U=require("hex-rgb"),d={screens:{sm:"640px",md:"768px",lg:"1024px",xl:"1280px","2xl":"1536px"},borderWidth:{none:"0",xs:"0.1rem",s:"0.2rem",m:"0.4rem"},colors:{transparent:"transparent",bg:{primary:"#f28133",primaryAccent:"#ad4c07",primarySubtle:"#fba56c",secondary:"#3481f2",secondaryAccent:"#074aad",secondarySubtle:"#4c93f7",body:"#fff"},bd:{primary:"#f28133",secondary:"#3481f2"},fg:{default:"#334155",accent:"#1161d7",cta:"#000",ctaInverse:"#fff"}},fontFamily:{openSans:'ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji"'},fontSize:{xs:"1rem",s:"1.2rem",m:"1.4rem",l:"1.6rem",xl:"1.8rem","2xl":"2rem","3xl":"2.4rem"},fontWeight:{regular:400,semibold:600,bold:700},lineHeight:{xs:"1.4rem",s:"1.7rem",m:"1.9rem",l:"2.2rem",xl:"2.4rem","2xl":"2.6rem","3xl":"2.8rem"},width:{pageMin:"320px",pageMax:"1066px"},borderRadius:{none:"0",xs:"0.4rem",s:"0.8rem",m:"1.6rem",l:"2.4rem",full:"100%"},boxShadow:{none:"none",normal:"0 -1px 4px 0 rgba(26, 26, 26, 0.08), 0 4px 8px 0 rgba(26, 26, 26, 0.12)",highlighted:"0 -1px 8px 0 rgba(26, 26, 26, 0.12), 0 4px 8px 0 rgba(0, 0, 0, 0.14)"},spacing:{auto:"auto",none:"0",xs:"0.4rem",s:"0.8rem",m:"1.6rem",l:"2.4rem",xl:"3.2rem",xxl:"4rem"},zIndex:{hide:-1,base:0,raised:1,dropdown:1e3,sticky:1100,overlay:1300,modal:1400,popover:1500,skipLink:1600,toast:1700,tooltip:1800}};function N(e){return Object.entries(e)}function l(e){return e.replace(/[A-Z]/g,r=>`-${r.toLocaleLowerCase()}`)}function O(e){return typeof e=="number"?!1:/^#[0-9a-fA-F]+$/.test(e)}function A(e){return typeof e=="string"||typeof e=="number"}function C(e,r=1){const t={};for(const n in e){const o=typeof e[n]=="object"?C(e[n],r+1):e[n];t[r>1?n.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase():n]=o}return t}function k(e){let r=function(n){var i;const o=n.slice(n.indexOf(":")+1);return o.replace(((i=o.match(/\/([^/]+)\.(jsx|js|tsx|ts|mjs|mts|cjs|cts)(?!$)/g))==null?void 0:i.at(0))||"","")}(e).replace(/\\/g,"/"),t="";return r[0]==="/"?(t="/",r=r.slice(1)):r[1]===":"&&(t=r.slice(0,3),r=r.slice(3)),{filepath:r,rootPath:t}}function H(e){const r=JSON.parse(JSON.stringify(e));return function t(n,o){N(n).forEach(([i,a])=>{if(a===null||typeof a!="object"){if(A(a)){const f=/--colors/.test(o||"")&&O(a)?`rgb(var(${o}-${l(i)}) / <alpha-value>)`:`var(${o}-${l(i)})`;n[i]=f}}else t(a,l((o?`--${o}-${i}`:`--${i}`).replace(/-{3,}/,"--")))})}(r),C(r)}const v=e=>Object.entries(e).map(([r,t])=>`${r}:${t}`).join(";"),R=e=>{return(r=e,Object.keys(r)).map(t=>{const i=function(a,f){const x={};return function F(T,u){N(T).forEach(([p,s])=>{if(s===null||typeof s!="object"){if(A(s)){const q=()=>{if(O(s)){const{red:E,green:I,blue:L}=U(s);return`${E} ${I} ${L}`}return s};x[`${u}-${l(p)}`]=q()}}else F(s,l((u?`--${u}-${p}`:`--${p}`).replace(/-{3,}/,"--")))})}(a),h($({},x),{className:f})}(e[t],t),{className:n}=i,o=S(i,["className"]);return t==="default"?`:root{${v(o)}}`:`.${n}{${v(o)}}`});var r};exports.createCSSTokensFile=function(e,r){const{filepath:t,rootPath:n}=k(w.join(j()||"",e));t.split("/").slice(0,-1).reduce((o,i)=>{const a=o+i+"/";return c.existsSync(a)||c.mkdirSync(a),a},n);try{c.appendFileSync(n+t,`
2
+ @tailwind base;
3
+ @tailwind components;
4
+ @tailwind utilities;
5
+ @layer base {${R(r).join("")}}
6
+ `,{flag:"w"}),console.log(`✨ CSS tokens file has been created 👉 ${e}`)}catch(o){console.error(o)}},exports.createTailwindThemeConfigFile=function(e){const{filepath:r,rootPath:t}=k(w.join(j()||"",e));r.split("/").slice(0,-1).reduce((n,o)=>{const i=n+o+"/";return c.existsSync(i)||c.mkdirSync(i),i},t);try{c.writeFileSync(t+r,`module.exports = ${JSON.stringify(H(d))}`,{flag:"w"}),console.log(`✨ Tailwind theme config file has been created 👉 ${e}`)}catch(n){console.error(n)}},exports.createTheme=function(e={}){return J(d,e)},exports.defaultTheme=d;
package/dist/index.mjs ADDED
@@ -0,0 +1,133 @@
1
+ var M = Object.defineProperty, P = Object.defineProperties;
2
+ var U = Object.getOwnPropertyDescriptors;
3
+ var l = Object.getOwnPropertySymbols;
4
+ var x = Object.prototype.hasOwnProperty, g = Object.prototype.propertyIsEnumerable;
5
+ var d = (e, r, t) => r in e ? M(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, b = (e, r) => {
6
+ for (var t in r || (r = {}))
7
+ x.call(r, t) && d(e, t, r[t]);
8
+ if (l)
9
+ for (var t of l(r))
10
+ g.call(r, t) && d(e, t, r[t]);
11
+ return e;
12
+ }, y = (e, r) => P(e, U(r));
13
+ var $ = (e, r) => {
14
+ var t = {};
15
+ for (var o in e)
16
+ x.call(e, o) && r.indexOf(o) < 0 && (t[o] = e[o]);
17
+ if (e != null && l)
18
+ for (var o of l(e))
19
+ r.indexOf(o) < 0 && g.call(e, o) && (t[o] = e[o]);
20
+ return t;
21
+ };
22
+ import H from "deepmerge";
23
+ import { existsSync as S, mkdirSync as j, writeFileSync as R, appendFileSync as W } from "fs";
24
+ import w from "parent-module";
25
+ import { join as k } from "path";
26
+ import Z from "hex-rgb";
27
+ const v = { screens: { sm: "640px", md: "768px", lg: "1024px", xl: "1280px", "2xl": "1536px" }, borderWidth: { none: "0", xs: "0.1rem", s: "0.2rem", m: "0.4rem" }, colors: { transparent: "transparent", bg: { primary: "#f28133", primaryAccent: "#ad4c07", primarySubtle: "#fba56c", secondary: "#3481f2", secondaryAccent: "#074aad", secondarySubtle: "#4c93f7", body: "#fff" }, bd: { primary: "#f28133", secondary: "#3481f2" }, fg: { default: "#334155", accent: "#1161d7", cta: "#000", ctaInverse: "#fff" } }, fontFamily: { openSans: 'ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji"' }, fontSize: { xs: "1rem", s: "1.2rem", m: "1.4rem", l: "1.6rem", xl: "1.8rem", "2xl": "2rem", "3xl": "2.4rem" }, fontWeight: { regular: 400, semibold: 600, bold: 700 }, lineHeight: { xs: "1.4rem", s: "1.7rem", m: "1.9rem", l: "2.2rem", xl: "2.4rem", "2xl": "2.6rem", "3xl": "2.8rem" }, width: { pageMin: "320px", pageMax: "1066px" }, borderRadius: { none: "0", xs: "0.4rem", s: "0.8rem", m: "1.6rem", l: "2.4rem", full: "100%" }, boxShadow: { none: "none", normal: "0 -1px 4px 0 rgba(26, 26, 26, 0.08), 0 4px 8px 0 rgba(26, 26, 26, 0.12)", highlighted: "0 -1px 8px 0 rgba(26, 26, 26, 0.12), 0 4px 8px 0 rgba(0, 0, 0, 0.14)" }, spacing: { auto: "auto", none: "0", xs: "0.4rem", s: "0.8rem", m: "1.6rem", l: "2.4rem", xl: "3.2rem", xxl: "4rem" }, zIndex: { hide: -1, base: 0, raised: 1, dropdown: 1e3, sticky: 1100, overlay: 1300, modal: 1400, popover: 1500, skipLink: 1600, toast: 1700, tooltip: 1800 } };
28
+ function Y(e = {}) {
29
+ return H(v, e);
30
+ }
31
+ function N(e) {
32
+ return Object.entries(e);
33
+ }
34
+ function c(e) {
35
+ return e.replace(/[A-Z]/g, (r) => `-${r.toLocaleLowerCase()}`);
36
+ }
37
+ function A(e) {
38
+ return typeof e == "number" ? !1 : /^#[0-9a-fA-F]+$/.test(e);
39
+ }
40
+ function C(e) {
41
+ return typeof e == "string" || typeof e == "number";
42
+ }
43
+ function F(e, r = 1) {
44
+ const t = {};
45
+ for (const o in e) {
46
+ const n = typeof e[o] == "object" ? F(e[o], r + 1) : e[o];
47
+ t[r > 1 ? o.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase() : o] = n;
48
+ }
49
+ return t;
50
+ }
51
+ function O(e) {
52
+ let r = function(o) {
53
+ var s;
54
+ const n = o.slice(o.indexOf(":") + 1);
55
+ return n.replace(((s = n.match(/\/([^/]+)\.(jsx|js|tsx|ts|mjs|mts|cjs|cts)(?!$)/g)) == null ? void 0 : s.at(0)) || "", "");
56
+ }(e).replace(/\\/g, "/"), t = "";
57
+ return r[0] === "/" ? (t = "/", r = r.slice(1)) : r[1] === ":" && (t = r.slice(0, 3), r = r.slice(3)), { filepath: r, rootPath: t };
58
+ }
59
+ function B(e) {
60
+ const r = JSON.parse(JSON.stringify(e));
61
+ return function t(o, n) {
62
+ N(o).forEach(([s, a]) => {
63
+ if (a === null || typeof a != "object") {
64
+ if (C(a)) {
65
+ const m = /--colors/.test(n || "") && A(a) ? `rgb(var(${n}-${c(s)}) / <alpha-value>)` : `var(${n}-${c(s)})`;
66
+ o[s] = m;
67
+ }
68
+ } else
69
+ t(a, c((n ? `--${n}-${s}` : `--${s}`).replace(/-{3,}/, "--")));
70
+ });
71
+ }(r), F(r);
72
+ }
73
+ function _(e) {
74
+ const { filepath: r, rootPath: t } = O(k(w() || "", e));
75
+ r.split("/").slice(0, -1).reduce((o, n) => {
76
+ const s = o + n + "/";
77
+ return S(s) || j(s), s;
78
+ }, t);
79
+ try {
80
+ R(t + r, `module.exports = ${JSON.stringify(B(v))}`, { flag: "w" }), console.log(`✨ Tailwind theme config file has been created 👉 ${e}`);
81
+ } catch (o) {
82
+ console.error(o);
83
+ }
84
+ }
85
+ const h = (e) => Object.entries(e).map(([r, t]) => `${r}:${t}`).join(";"), q = (e) => {
86
+ return (r = e, Object.keys(r)).map((t) => {
87
+ const s = function(a, m) {
88
+ const u = {};
89
+ return function T(E, f) {
90
+ N(E).forEach(([p, i]) => {
91
+ if (i === null || typeof i != "object") {
92
+ if (C(i)) {
93
+ const I = () => {
94
+ if (A(i)) {
95
+ const { red: L, green: z, blue: J } = Z(i);
96
+ return `${L} ${z} ${J}`;
97
+ }
98
+ return i;
99
+ };
100
+ u[`${f}-${c(p)}`] = I();
101
+ }
102
+ } else
103
+ T(i, c((f ? `--${f}-${p}` : `--${p}`).replace(/-{3,}/, "--")));
104
+ });
105
+ }(a), y(b({}, u), { className: m });
106
+ }(e[t], t), { className: o } = s, n = $(s, ["className"]);
107
+ return t === "default" ? `:root{${h(n)}}` : `.${o}{${h(n)}}`;
108
+ });
109
+ var r;
110
+ };
111
+ function ee(e, r) {
112
+ const { filepath: t, rootPath: o } = O(k(w() || "", e));
113
+ t.split("/").slice(0, -1).reduce((n, s) => {
114
+ const a = n + s + "/";
115
+ return S(a) || j(a), a;
116
+ }, o);
117
+ try {
118
+ W(o + t, `
119
+ @tailwind base;
120
+ @tailwind components;
121
+ @tailwind utilities;
122
+ @layer base {${q(r).join("")}}
123
+ `, { flag: "w" }), console.log(`✨ CSS tokens file has been created 👉 ${e}`);
124
+ } catch (n) {
125
+ console.error(n);
126
+ }
127
+ }
128
+ export {
129
+ ee as createCSSTokensFile,
130
+ _ as createTailwindThemeConfigFile,
131
+ Y as createTheme,
132
+ v as defaultTheme
133
+ };
@@ -0,0 +1,103 @@
1
+ export interface Theme {
2
+ screens: {
3
+ sm: string;
4
+ md: string;
5
+ lg: string;
6
+ xl: string;
7
+ '2xl': string;
8
+ };
9
+ borderWidth: {
10
+ none: string;
11
+ xs: string;
12
+ s: string;
13
+ m: string;
14
+ };
15
+ colors: {
16
+ transparent: string;
17
+ bg: {
18
+ body: string;
19
+ primary: string;
20
+ primaryAccent: string;
21
+ primarySubtle: string;
22
+ secondary: string;
23
+ secondaryAccent: string;
24
+ secondarySubtle: string;
25
+ };
26
+ fg: {
27
+ default: string;
28
+ accent: string;
29
+ cta: string;
30
+ ctaInverse: string;
31
+ };
32
+ bd: {
33
+ primary: string;
34
+ secondary: string;
35
+ };
36
+ };
37
+ fontFamily: {
38
+ openSans: string;
39
+ };
40
+ fontSize: {
41
+ xs: string;
42
+ s: string;
43
+ m: string;
44
+ l: string;
45
+ xl: string;
46
+ '2xl': string;
47
+ '3xl': string;
48
+ };
49
+ fontWeight: {
50
+ regular: number;
51
+ semibold: number;
52
+ bold: number;
53
+ };
54
+ lineHeight: {
55
+ xs: string;
56
+ s: string;
57
+ m: string;
58
+ l: string;
59
+ xl: string;
60
+ '2xl': string;
61
+ '3xl': string;
62
+ };
63
+ width: {
64
+ pageMin: string;
65
+ pageMax: string;
66
+ };
67
+ borderRadius: {
68
+ none: string;
69
+ xs: string;
70
+ s: string;
71
+ m: string;
72
+ l: string;
73
+ full: string;
74
+ };
75
+ boxShadow: {
76
+ none: string;
77
+ normal: string;
78
+ highlighted: string;
79
+ };
80
+ spacing: {
81
+ auto: string;
82
+ none: string;
83
+ xs: string;
84
+ s: string;
85
+ m: string;
86
+ l: string;
87
+ xl: string;
88
+ xxl: string;
89
+ };
90
+ zIndex: {
91
+ hide: number;
92
+ base: number;
93
+ raised: number;
94
+ dropdown: number;
95
+ sticky: number;
96
+ overlay: number;
97
+ modal: number;
98
+ popover: number;
99
+ skipLink: number;
100
+ toast: number;
101
+ tooltip: number;
102
+ };
103
+ }
@@ -0,0 +1,11 @@
1
+ declare function objectKeys<T extends Record<string | number, unknown>>(obj: T): (keyof T)[];
2
+ declare function objectEntries<T extends Record<string | number, unknown>>(obj: T): [keyof T, T[keyof T]][];
3
+ declare function toKebabCase(v: string): string;
4
+ declare function isHex(value: string | number): value is string;
5
+ declare function isStringOrNumber(value: unknown): value is string | number;
6
+ declare function toKebabCaseKeys<T extends Object>(obj: T, level?: number): Record<string, T[keyof T]>;
7
+ declare function buildFilePath(path: string): {
8
+ filepath: string;
9
+ rootPath: string;
10
+ };
11
+ export { objectKeys, objectEntries, toKebabCase, isHex, toKebabCaseKeys, buildFilePath, isStringOrNumber, };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@spark-ui/theme-utils",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Theme configuration",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "main": "./dist/index.js",
8
+ "main": "./dist/index.mjs",
9
9
  "module": "./dist/index.mjs",
10
- "types": "./dist/index.d.mts",
10
+ "types": "./dist/index.d.ts",
11
11
  "scripts": {
12
12
  "build": "vite build"
13
13
  },
@@ -17,5 +17,5 @@
17
17
  "parent-module": "3.0.0",
18
18
  "type-fest": "3.5.6"
19
19
  },
20
- "gitHead": "807a2fbdf384a277d4110cff7dbb549bb9ab4563"
20
+ "gitHead": "a854685e736add2fe4854ecd6bef7272ea4ab82f"
21
21
  }
package/tsconfig.json CHANGED
@@ -1,10 +1,4 @@
1
1
  {
2
2
  "extends": "../../../tsconfig.json",
3
- "compilerOptions": {
4
- "baseUrl": ".",
5
- "rootDir": "./",
6
- "outDir": "./dist",
7
- "declaration": true,
8
- },
9
- "include": ["**/*", "../../global.d.ts"]
3
+ "include": ["src/**/*", "../../global.d.ts"]
10
4
  }
package/vite.config.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import path from 'path'
2
2
  import { terser } from 'rollup-plugin-terser'
3
- import typescript from '@rollup/plugin-typescript'
3
+ import dts from 'vite-plugin-dts'
4
4
 
5
5
  const pkg = require(path.resolve(__dirname, './package.json'))
6
6
 
@@ -11,14 +11,18 @@ export default {
11
11
  build: {
12
12
  target: 'es2015',
13
13
  lib: {
14
- entry: 'index.mts',
14
+ entry: 'src/index.ts',
15
15
  formats: ['es', 'cjs'],
16
16
  fileName: 'index',
17
17
  },
18
18
  rollupOptions: {
19
19
  external: [...deps, ...devDeps, 'path', 'fs'],
20
- preserveModules: false,
21
- plugins: [terser(), typescript({ cacheDir: './dist' })],
20
+ plugins: [terser()],
22
21
  },
23
22
  },
23
+ plugins: [
24
+ dts({
25
+ entryRoot: './src',
26
+ }),
27
+ ],
24
28
  }
@@ -1,101 +0,0 @@
1
- import { appendFileSync, existsSync, mkdirSync } from 'fs'
2
- import hexRgb from 'hex-rgb'
3
- import parentModule from 'parent-module'
4
- import { join } from 'path'
5
-
6
- import type { Theme } from './types.mjs'
7
- import {
8
- buildFilePath,
9
- isHex,
10
- isStringOrNumber,
11
- objectEntries,
12
- objectKeys,
13
- toKebabCase,
14
- } from './utils.mjs'
15
-
16
- /* eslint-disable-next-line @typescript-eslint/ban-types */
17
- type FlattenedTheme = Record<'className' | (string & {}), string | number>
18
- type NestedObj = Record<string, string | number | Record<string, string | number>>
19
-
20
- function flattenTheme(theme: Theme, className: string): FlattenedTheme {
21
- const flattenedTheme = {} as FlattenedTheme
22
-
23
- function flatten(obj: Theme, path?: string) {
24
- objectEntries(obj as unknown as NestedObj).forEach(([key, value]) => {
25
- if (value !== null && typeof value === 'object') {
26
- const formattedPath = path ? `--${path}-${key}` : `--${key}`
27
- flatten(value as unknown as Theme, toKebabCase(formattedPath.replace(/-{3,}/, '--')))
28
-
29
- return
30
- }
31
-
32
- if (isStringOrNumber(value)) {
33
- const getFormattedValue = () => {
34
- if (isHex(value)) {
35
- const { red, green, blue } = hexRgb(value)
36
-
37
- return `${red} ${green} ${blue}`
38
- }
39
-
40
- return value
41
- }
42
-
43
- flattenedTheme[`${path}-${toKebabCase(key as string)}`] = getFormattedValue()
44
- }
45
- })
46
- }
47
-
48
- flatten(theme)
49
-
50
- return {
51
- ...flattenedTheme,
52
- className,
53
- }
54
- }
55
-
56
- const toStringifiedTheme = (theme: Record<string, string | number>) =>
57
- Object.entries(theme)
58
- .map(([k, v]) => `${k}:${v}`)
59
- .join(';')
60
-
61
- const getStringifiedThemes = (themeRecord: Record<string, Theme>) =>
62
- objectKeys(themeRecord).map(key => {
63
- const { className, ...rest } = flattenTheme(themeRecord[key] as Theme, key)
64
-
65
- return key === 'default'
66
- ? `:root{${toStringifiedTheme(rest)}}`
67
- : `.${className}{${toStringifiedTheme(rest)}}`
68
- })
69
-
70
- export function createCSSTokensFile(path: string, themeRecord: Record<string, Theme>) {
71
- const { filepath, rootPath } = buildFilePath(join(parentModule() || '', path))
72
-
73
- const folders = filepath.split('/').slice(0, -1)
74
- folders.reduce((acc, folder) => {
75
- const folderPath = acc + folder + '/'
76
- if (!existsSync(folderPath)) {
77
- mkdirSync(folderPath)
78
- }
79
-
80
- return folderPath
81
- }, rootPath)
82
-
83
- try {
84
- appendFileSync(
85
- rootPath + filepath,
86
- `
87
- @tailwind base;
88
- @tailwind components;
89
- @tailwind utilities;
90
- @layer base {${getStringifiedThemes(themeRecord).join('')}}
91
- `,
92
- {
93
- flag: 'w',
94
- }
95
- )
96
-
97
- console.log(`✨ CSS tokens file has been created 👉 ${path}`)
98
- } catch (error) {
99
- console.error(error)
100
- }
101
- }
@@ -1,76 +0,0 @@
1
- import { existsSync, mkdirSync, writeFileSync } from 'fs'
2
- import parentModule from 'parent-module'
3
- import { join } from 'path'
4
-
5
- import { defaultTheme } from './defaultTheme.mjs'
6
- import type { Theme } from './types.mjs'
7
- import {
8
- buildFilePath,
9
- isHex,
10
- isStringOrNumber,
11
- objectEntries,
12
- toKebabCase,
13
- toKebabCaseKeys,
14
- } from './utils.mjs'
15
-
16
- type NestedObj = Record<string, string | number | Record<string, string | number>>
17
- type TailwindConfig = Record<string, Theme[keyof Theme]>
18
-
19
- function toTailwindConfig(theme: Theme): TailwindConfig {
20
- const themeCpy: Theme = JSON.parse(JSON.stringify(theme))
21
-
22
- function flatten(obj: Theme, path?: string) {
23
- objectEntries(obj as unknown as NestedObj).forEach(([key, value]) => {
24
- if (value !== null && typeof value === 'object') {
25
- const formattedPath = path ? `--${path}-${key}` : `--${key}`
26
- flatten(value as unknown as Theme, toKebabCase(formattedPath.replace(/-{3,}/, '--')))
27
-
28
- return
29
- }
30
-
31
- /* eslint-disable */
32
- if (isStringOrNumber(value)) {
33
- const formattedPath =
34
- /--colors/.test(path || '') && isHex(value)
35
- ? `rgb(var(${path}-${toKebabCase(key as string)}) / <alpha-value>)`
36
- : `var(${path}-${toKebabCase(key as string)})`
37
-
38
- /* @ts-ignore */
39
- obj[key as any] = formattedPath
40
- /* eslint-enable */
41
- }
42
- })
43
- }
44
-
45
- flatten(themeCpy)
46
-
47
- return toKebabCaseKeys(themeCpy)
48
- }
49
-
50
- export function createTailwindConfigFile(path: string) {
51
- const { filepath, rootPath } = buildFilePath(join(parentModule() || '', path))
52
-
53
- const folders = filepath.split('/').slice(0, -1)
54
- folders.reduce((acc, folder) => {
55
- const folderPath = acc + folder + '/'
56
- if (!existsSync(folderPath)) {
57
- mkdirSync(folderPath)
58
- }
59
-
60
- return folderPath
61
- }, rootPath)
62
-
63
- try {
64
- writeFileSync(
65
- rootPath + filepath,
66
- `module.exports = ${JSON.stringify(toTailwindConfig(defaultTheme))}`,
67
- {
68
- flag: 'w',
69
- }
70
- )
71
-
72
- console.log(`✨ Tailwind theme config file has been created 👉 ${path}`)
73
- } catch (error) {
74
- console.error(error)
75
- }
76
- }
package/createTheme.mts DELETED
@@ -1,9 +0,0 @@
1
- import deepMerge from 'deepmerge'
2
- import { PartialDeep } from 'type-fest'
3
-
4
- import { defaultTheme } from './defaultTheme.mjs'
5
- import type { Theme } from './types.mjs'
6
-
7
- export function createTheme(theme: PartialDeep<Theme> = {}): Theme {
8
- return deepMerge<Theme, PartialDeep<Theme>>(defaultTheme, theme)
9
- }
package/defaultTheme.mts DELETED
@@ -1,106 +0,0 @@
1
- import type { Theme } from './types.mjs'
2
-
3
- export const defaultTheme: Theme = {
4
- screens: {
5
- sm: '640px',
6
- md: '768px',
7
- lg: '1024px',
8
- xl: '1280px',
9
- '2xl': '1536px',
10
- },
11
- borderWidth: {
12
- none: '0',
13
- xs: '0.1rem',
14
- s: '0.2rem',
15
- m: '0.4rem',
16
- },
17
- colors: {
18
- transparent: 'transparent',
19
- bg: {
20
- primary: '#f28133',
21
- primaryAccent: '#ad4c07',
22
- primarySubtle: '#fba56c',
23
- secondary: '#3481f2',
24
- secondaryAccent: '#074aad',
25
- secondarySubtle: '#4c93f7',
26
- body: '#fff',
27
- },
28
- bd: {
29
- primary: '#f28133',
30
- secondary: '#3481f2',
31
- },
32
- fg: {
33
- default: '#334155',
34
- accent: '#1161d7',
35
- cta: '#000',
36
- ctaInverse: '#fff',
37
- },
38
- },
39
- fontFamily: {
40
- openSans:
41
- 'ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji"',
42
- },
43
- fontSize: {
44
- xs: '1rem',
45
- s: '1.2rem',
46
- m: '1.4rem',
47
- l: '1.6rem',
48
- xl: '1.8rem',
49
- '2xl': '2rem',
50
- '3xl': '2.4rem',
51
- },
52
- fontWeight: {
53
- regular: 400,
54
- semibold: 600,
55
- bold: 700,
56
- },
57
- lineHeight: {
58
- xs: '1.4rem',
59
- s: '1.7rem',
60
- m: '1.9rem',
61
- l: '2.2rem',
62
- xl: '2.4rem',
63
- '2xl': '2.6rem',
64
- '3xl': '2.8rem',
65
- },
66
- width: {
67
- pageMin: '320px',
68
- pageMax: '1066px',
69
- },
70
- borderRadius: {
71
- none: '0',
72
- xs: '0.4rem',
73
- s: '0.8rem',
74
- m: '1.6rem',
75
- l: '2.4rem',
76
- full: '100%',
77
- },
78
- boxShadow: {
79
- none: 'none',
80
- normal: '0 -1px 4px 0 rgba(26, 26, 26, 0.08), 0 4px 8px 0 rgba(26, 26, 26, 0.12)',
81
- highlighted: '0 -1px 8px 0 rgba(26, 26, 26, 0.12), 0 4px 8px 0 rgba(0, 0, 0, 0.14)',
82
- },
83
- spacing: {
84
- auto: 'auto',
85
- none: '0',
86
- xs: '0.4rem',
87
- s: '0.8rem',
88
- m: '1.6rem',
89
- l: '2.4rem',
90
- xl: '3.2rem',
91
- xxl: '4rem',
92
- },
93
- zIndex: {
94
- hide: -1,
95
- base: 0,
96
- raised: 1,
97
- dropdown: 1000,
98
- sticky: 1100,
99
- overlay: 1300,
100
- modal: 1400,
101
- popover: 1500,
102
- skipLink: 1600,
103
- toast: 1700,
104
- tooltip: 1800,
105
- },
106
- }
package/index.mts DELETED
@@ -1,6 +0,0 @@
1
- export { createTheme } from './createTheme.mjs'
2
- export { createTailwindConfigFile } from './createTailwindConfigFile.mjs'
3
- export { createCSSTokensFile } from './createCSSTokensFile.mjs'
4
- export { defaultTheme } from './defaultTheme.mjs'
5
-
6
- export type { Theme } from './types.mjs'
package/types.mts DELETED
@@ -1,103 +0,0 @@
1
- export interface Theme {
2
- screens: {
3
- sm: string
4
- md: string
5
- lg: string
6
- xl: string
7
- '2xl': string
8
- }
9
- borderWidth: {
10
- none: string
11
- xs: string
12
- s: string
13
- m: string
14
- }
15
- colors: {
16
- transparent: string
17
- bg: {
18
- body: string
19
- primary: string
20
- primaryAccent: string
21
- primarySubtle: string
22
- secondary: string
23
- secondaryAccent: string
24
- secondarySubtle: string
25
- }
26
- fg: {
27
- default: string
28
- accent: string
29
- cta: string
30
- ctaInverse: string
31
- }
32
- bd: {
33
- primary: string
34
- secondary: string
35
- }
36
- }
37
- fontFamily: {
38
- openSans: string
39
- }
40
- fontSize: {
41
- xs: string
42
- s: string
43
- m: string
44
- l: string
45
- xl: string
46
- '2xl': string
47
- '3xl': string
48
- }
49
- fontWeight: {
50
- regular: number
51
- semibold: number
52
- bold: number
53
- }
54
- lineHeight: {
55
- xs: string
56
- s: string
57
- m: string
58
- l: string
59
- xl: string
60
- '2xl': string
61
- '3xl': string
62
- }
63
- width: {
64
- pageMin: string
65
- pageMax: string
66
- }
67
- borderRadius: {
68
- none: string
69
- xs: string
70
- s: string
71
- m: string
72
- l: string
73
- full: string
74
- }
75
- boxShadow: {
76
- none: string
77
- normal: string
78
- highlighted: string
79
- }
80
- spacing: {
81
- auto: string
82
- none: string
83
- xs: string
84
- s: string
85
- m: string
86
- l: string
87
- xl: string
88
- xxl: string
89
- }
90
- zIndex: {
91
- hide: number
92
- base: number
93
- raised: number
94
- dropdown: number
95
- sticky: number
96
- overlay: number
97
- modal: number
98
- popover: number
99
- skipLink: number
100
- toast: number
101
- tooltip: number
102
- }
103
- }
package/utils.mts DELETED
@@ -1,71 +0,0 @@
1
- function objectKeys<T extends Record<string | number, unknown>>(obj: T): (keyof T)[] {
2
- return Object.keys(obj) as (keyof T)[]
3
- }
4
-
5
- function objectEntries<T extends Record<string | number, unknown>>(
6
- obj: T
7
- ): [keyof T, T[keyof T]][] {
8
- return Object.entries(obj) as [keyof T, T[keyof T]][]
9
- }
10
-
11
- function toKebabCase(v: string) {
12
- return v.replace(/[A-Z]/g, e => `-${e.toLocaleLowerCase()}`)
13
- }
14
-
15
- function isHex(value: string | number): value is string {
16
- if (typeof value === 'number') {
17
- return false
18
- }
19
-
20
- const regexp = /^#[0-9a-fA-F]+$/
21
-
22
- return regexp.test(value)
23
- }
24
-
25
- function isStringOrNumber(value: unknown): value is string | number {
26
- return typeof value === 'string' || typeof value === 'number'
27
- }
28
-
29
- // eslint-disable-next-line @typescript-eslint/ban-types
30
- function toKebabCaseKeys<T extends Object>(obj: T, level = 1): Record<string, T[keyof T]> {
31
- const result: any = {}
32
- for (const key in obj) {
33
- const value =
34
- typeof obj[key] === 'object' ? toKebabCaseKeys(obj[key] as T, level + 1) : obj[key]
35
- result[level > 1 ? key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase() : key] = value
36
- }
37
-
38
- return result
39
- }
40
-
41
- function getFormattedPath(input: string) {
42
- const preFormat = input.slice(input.indexOf(':') + 1)
43
- const extensionRegex = /\/([^/]+)\.(jsx|js|tsx|ts|mjs|mts|cjs|cts)(?!$)/g
44
-
45
- return preFormat.replace(preFormat.match(extensionRegex)?.at(0) || '', '')
46
- }
47
-
48
- function buildFilePath(path: string) {
49
- let filepath = getFormattedPath(path).replace(/\\/g, '/')
50
-
51
- let rootPath = ''
52
- if (filepath[0] === '/') {
53
- rootPath = '/'
54
- filepath = filepath.slice(1)
55
- } else if (filepath[1] === ':') {
56
- rootPath = filepath.slice(0, 3)
57
- filepath = filepath.slice(3)
58
- }
59
-
60
- return { filepath, rootPath }
61
- }
62
-
63
- export {
64
- objectKeys,
65
- objectEntries,
66
- toKebabCase,
67
- isHex,
68
- toKebabCaseKeys,
69
- buildFilePath,
70
- isStringOrNumber,
71
- }