@udixio/tailwind 0.5.2 → 1.0.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.
@@ -0,0 +1,75 @@
1
+ import plugin, { PluginAPI } from 'tailwindcss/plugin';
2
+
3
+ export type StateOptions = {
4
+ colorKeys: string[];
5
+ };
6
+
7
+ type Components = Record<string, Record<string, object>>;
8
+
9
+ const defaultConfig = {
10
+ statePrefix: 'state',
11
+ disabledStyles: {
12
+ textOpacity: 0.38,
13
+ backgroundOpacity: 0.12,
14
+ },
15
+ transition: {
16
+ duration: 150,
17
+ },
18
+ };
19
+
20
+ export const state = plugin.withOptions(({ colorKeys }: StateOptions) => {
21
+ const resolved = {
22
+ ...defaultConfig,
23
+ disabledStyles: {
24
+ ...defaultConfig.disabledStyles,
25
+ ...{},
26
+ },
27
+ transition: {
28
+ ...defaultConfig.transition,
29
+ ...{},
30
+ },
31
+ };
32
+
33
+ return ({ addComponents }: PluginAPI) => {
34
+ const newComponents: Components = {};
35
+
36
+ for (const isGroup of [false, true]) {
37
+ const group = isGroup ? 'group-' : '';
38
+ for (const colorName of colorKeys) {
39
+ const className = `.${group}${resolved.statePrefix}-${colorName}`;
40
+ newComponents[className] = {
41
+ [`@apply ${group}hover:bg-${colorName}/[0.08]`]: {},
42
+ [`@apply ${group}active:bg-${colorName}/[0.12]`]: {},
43
+ [`@apply ${group}focus-visible:bg-${colorName}/[0.12]`]: {},
44
+ [`@apply transition-colors`]: {},
45
+ [`@apply duration-${resolved.transition.duration}`]: {},
46
+ [`@apply ${group}disabled:text-on-surface/[${resolved.disabledStyles.textOpacity}]`]:
47
+ {},
48
+ [`@apply ${group}disabled:bg-on-surface/[${resolved.disabledStyles.backgroundOpacity}]`]:
49
+ {},
50
+ };
51
+ }
52
+ }
53
+
54
+ for (const colorName of colorKeys) {
55
+ for (const stateName of ['hover', 'active', 'focus', 'disabled']) {
56
+ const className = `.${stateName}-${resolved.statePrefix}-${colorName}`;
57
+ if (stateName === 'disabled') {
58
+ newComponents[className] = {
59
+ [`@apply text-on-surface/[${resolved.disabledStyles.textOpacity}]`]:
60
+ {},
61
+ [`@apply bg-on-surface/[${resolved.disabledStyles.backgroundOpacity}]`]:
62
+ {},
63
+ };
64
+ } else {
65
+ const opacity = stateName === 'hover' ? 0.08 : 0.12;
66
+ newComponents[className] = {
67
+ [`@apply bg-${colorName}/[${opacity}]`]: {},
68
+ };
69
+ }
70
+ }
71
+ }
72
+
73
+ addComponents(newComponents);
74
+ };
75
+ });
@@ -0,0 +1,130 @@
1
+ import {
2
+ createOrUpdateFile,
3
+ findTailwindCssFile,
4
+ getFileContent,
5
+ replaceFileContent,
6
+ } from './file';
7
+ import path from 'path';
8
+ import { FontPlugin, PluginAbstract, PluginImplAbstract } from '@udixio/theme';
9
+ import { ConfigCss } from './main';
10
+
11
+ interface TailwindPluginOptions {
12
+ // darkMode?: 'class' | 'media';
13
+ responsiveBreakPoints?: Record<string, number>;
14
+ styleFilePath?: string;
15
+ // subThemes?: Record<string, string>;
16
+ }
17
+
18
+ export class TailwindPlugin extends PluginAbstract<
19
+ TailwindImplPlugin,
20
+ TailwindPluginOptions
21
+ > {
22
+ public dependencies = [FontPlugin];
23
+ public name = 'tailwind';
24
+ pluginClass = TailwindImplPlugin;
25
+ }
26
+
27
+ class TailwindImplPlugin extends PluginImplAbstract<TailwindPluginOptions> {
28
+ onInit() {
29
+ this.options.responsiveBreakPoints ??= {
30
+ lg: 1.125,
31
+ };
32
+ }
33
+
34
+ onLoad() {
35
+ const searchKeyword = "@import 'tailwindcss';";
36
+
37
+ const tailwindCssPath =
38
+ this.options.styleFilePath ??
39
+ findTailwindCssFile(process.cwd(), searchKeyword);
40
+ if (!tailwindCssPath) {
41
+ throw new Error('The style file containing tailwind was not found.');
42
+ }
43
+ const searchPattern = /@import ["']tailwindcss["'];/;
44
+ const replacement = `@import 'tailwindcss';\n@import "./udixio.css";`;
45
+
46
+ if (!getFileContent(tailwindCssPath, /@import\s+"\.\/udixio\.css";/)) {
47
+ replaceFileContent(tailwindCssPath, searchPattern, replacement);
48
+ }
49
+
50
+ const cssFilePath = path.dirname(tailwindCssPath);
51
+
52
+ const colors: Record<
53
+ string,
54
+ {
55
+ light: string;
56
+ dark: string;
57
+ }
58
+ > = {};
59
+
60
+ for (const isDark of [false, true]) {
61
+ this.api.themes.update({ isDark: isDark });
62
+ for (const [key, value] of this.api.colors.getColors().entries()) {
63
+ const newKey = key
64
+ .replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2')
65
+ .toLowerCase();
66
+ colors[newKey] ??= { light: '', dark: '' };
67
+ colors[newKey][isDark ? 'dark' : 'light'] = value.getHex();
68
+ }
69
+ }
70
+
71
+ const { fontStyles, fontFamily } = this.api.plugins
72
+ .getPlugin(FontPlugin)
73
+ .getInstance()
74
+ .getFonts();
75
+
76
+ const configCss: ConfigCss = {
77
+ colorKeys: Object.keys(colors).join(', '),
78
+ fontStyles: Object.entries(fontStyles)
79
+ .map(([fontRole, fontStyle]) =>
80
+ Object.entries(fontStyle)
81
+ .map(
82
+ ([fontSize, fontStyle]) =>
83
+ `${fontRole}-${fontSize} ${Object.entries(fontStyle)
84
+ .map(([name, value]) => `${name}[${value}]`)
85
+ .join(' ')}`,
86
+ )
87
+ .join(', '),
88
+ )
89
+ .join(', '),
90
+ responsiveBreakPoints: Object.entries(
91
+ this.options.responsiveBreakPoints ?? {},
92
+ )
93
+ .map(([key, value]) => `${key} ${value}`)
94
+ .join(', '),
95
+ };
96
+
97
+ createOrUpdateFile(
98
+ path.join(cssFilePath, 'udixio.css'),
99
+ `
100
+ @plugin "@udixio/tailwind" {
101
+ colorKeys: ${configCss.colorKeys};
102
+ fontStyles: ${configCss.fontStyles};
103
+ responsiveBreakPoints: ${configCss.responsiveBreakPoints};
104
+ }
105
+ @custom-variant dark (&:where(.dark, .dark *));
106
+ @theme {
107
+ --color-*: initial;
108
+ ${Object.entries(colors)
109
+ .map(([key, value]) => `--color-${key}: ${value.light};`)
110
+ .join('\n ')}
111
+ }
112
+ @layer theme {
113
+ .dark {
114
+ ${Object.entries(colors)
115
+ .map(([key, value]) => `--color-${key}: ${value.dark};`)
116
+ .join('\n ')}
117
+ }
118
+ }
119
+ @theme {
120
+ ${Object.entries(fontFamily)
121
+ .map(
122
+ ([key, values]) =>
123
+ `--font-${key}: ${values.map((value) => `"${value}"`).join(', ')};`,
124
+ )
125
+ .join('\n ')}
126
+ }
127
+ `,
128
+ );
129
+ }
130
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "files": [],
4
+ "include": [],
5
+ "references": [
6
+ {
7
+ "path": "../theme"
8
+ },
9
+ {
10
+ "path": "./tsconfig.lib.json"
11
+ },
12
+ {
13
+ "path": "./tsconfig.spec.json"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,37 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "baseUrl": ".",
5
+ "rootDir": "src",
6
+ "outDir": "dist",
7
+ "tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
8
+ "emitDeclarationOnly": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "types": [
11
+ "node",
12
+ "vite/client"
13
+ ]
14
+ },
15
+ "include": [
16
+ "src/**/*.ts"
17
+ ],
18
+ "references": [
19
+ {
20
+ "path": "../theme/tsconfig.lib.json"
21
+ }
22
+ ],
23
+ "exclude": [
24
+ "vite.config.ts",
25
+ "vite.config.mts",
26
+ "vitest.config.ts",
27
+ "vitest.config.mts",
28
+ "src/**/*.test.ts",
29
+ "src/**/*.spec.ts",
30
+ "src/**/*.test.tsx",
31
+ "src/**/*.spec.tsx",
32
+ "src/**/*.test.js",
33
+ "src/**/*.spec.js",
34
+ "src/**/*.test.jsx",
35
+ "src/**/*.spec.jsx"
36
+ ]
37
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./out-tsc/vitest",
5
+ "types": [
6
+ "vitest/globals",
7
+ "vitest/importMeta",
8
+ "vite/client",
9
+ "node",
10
+ "vitest"
11
+ ],
12
+ "module": "nodenext",
13
+ "moduleResolution": "nodenext",
14
+ "forceConsistentCasingInFileNames": true
15
+ },
16
+ "include": [
17
+ "vite.config.ts",
18
+ "vite.config.mts",
19
+ "vitest.config.ts",
20
+ "vitest.config.mts",
21
+ "src/**/*.test.ts",
22
+ "src/**/*.spec.ts",
23
+ "src/**/*.test.tsx",
24
+ "src/**/*.spec.tsx",
25
+ "src/**/*.test.js",
26
+ "src/**/*.spec.js",
27
+ "src/**/*.test.jsx",
28
+ "src/**/*.spec.jsx",
29
+ "src/**/*.d.ts"
30
+ ],
31
+ "references": [
32
+ {
33
+ "path": "./tsconfig.lib.json"
34
+ }
35
+ ]
36
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,54 @@
1
+ /// <reference types='vitest' />
2
+ import { defineConfig } from 'vite';
3
+ import dts from 'vite-plugin-dts';
4
+ import * as path from 'path';
5
+
6
+ export default defineConfig(() => ({
7
+ root: __dirname,
8
+ cacheDir: '../../node_modules/.vite/packages/tailwind',
9
+ plugins: [
10
+ dts({
11
+ entryRoot: 'src',
12
+ tsconfigPath: path.join(__dirname, 'tsconfig.lib.json'),
13
+ }),
14
+ ],
15
+ // Uncomment this if you are using workers.
16
+ // worker: {
17
+ // plugins: [ nxViteTsPaths() ],
18
+ // },
19
+ // Configuration for building your library.
20
+ // See: https://vitejs.dev/guide/build.html#library-mode
21
+ build: {
22
+ outDir: './dist',
23
+ emptyOutDir: true,
24
+ reportCompressedSize: true,
25
+ ssr: true,
26
+ commonjsOptions: {
27
+ transformMixedEsModules: true,
28
+ },
29
+ lib: {
30
+ // Could also be a dictionary or array of multiple entry points.
31
+ entry: 'src/index.ts',
32
+ name: '@udixio/tailwind',
33
+ fileName: 'index',
34
+ // Change this to the formats you want to support.
35
+ // Don't forget to update your package.json as well.
36
+ formats: ['es' as const, 'cjs' as const],
37
+ },
38
+ rollupOptions: {
39
+ // External packages that should not be bundled into your library.
40
+ external: ['tailwindcss', '@udixio/theme'],
41
+ },
42
+ },
43
+ test: {
44
+ watch: false,
45
+ globals: true,
46
+ environment: 'node',
47
+ include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
48
+ reporters: ['default'],
49
+ coverage: {
50
+ reportsDirectory: './test-output/vitest/coverage',
51
+ provider: 'v8' as const,
52
+ },
53
+ },
54
+ }));
package/src/file.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../../packages/tailwind/src/file.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,EAAE,SAAS,MAAM,KAAG,IAmBtE,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,UAAU,MAAM,EAChB,gBAAgB,MAAM,GAAG,MAAM,KAC9B,MAAM,GAAG,KAAK,GAAG,IA4CnB,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,UAAU,MAAM,EAChB,eAAe,MAAM,GAAG,MAAM,EAC9B,aAAa,MAAM,KAClB,IAkBF,CAAC;AACF,eAAO,MAAM,mBAAmB,GAC9B,UAAU,MAAM,EAChB,eAAe,MAAM,KACpB,MAAM,GAAG,IAyBX,CAAC"}
package/src/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { createTheme } from './main';
2
- export * from './main';
3
- export * from './plugins-tailwind';
4
- export * from './tailwind.plugin';
5
- export default createTheme;
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/tailwind/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,eAAe,WAAW,CAAC"}
package/src/main.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { default as plugin } from 'tailwindcss/plugin';
2
- export declare const createTheme: () => Promise<ReturnType<typeof plugin.withOptions>>;
3
- //# sourceMappingURL=main.d.ts.map
package/src/main.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../../packages/tailwind/src/main.ts"],"names":[],"mappings":"AAEA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AAExC,eAAO,MAAM,WAAW,EAAE,MAAM,OAAO,CACrC,UAAU,CAAC,OAAO,MAAM,CAAC,WAAW,CAAC,CAKtC,CAAC"}
@@ -1,4 +0,0 @@
1
- import { FontRole, FontSize, FontStyle } from '@udixio/theme';
2
- import { default as plugin } from 'tailwindcss/plugin';
3
- export declare const font: (fontStyles: Record<FontRole, Record<FontSize, FontStyle>>, responsiveBreakPoints: Record<string, number>) => ReturnType<typeof plugin>;
4
- //# sourceMappingURL=font.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"font.d.ts","sourceRoot":"","sources":["../../../../../packages/tailwind/src/plugins-tailwind/font.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,MAAqB,MAAM,oBAAoB,CAAC;AAEvD,eAAO,MAAM,IAAI,EAAE,CACjB,UAAU,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,EACzD,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAC1C,UAAU,CAAC,OAAO,MAAM,CA2D5B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/tailwind/src/plugins-tailwind/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
@@ -1,3 +0,0 @@
1
- import { default as plugin } from 'tailwindcss/plugin';
2
- export declare const state: (colorKeys: string[]) => ReturnType<typeof plugin>;
3
- //# sourceMappingURL=state.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../../../packages/tailwind/src/plugins-tailwind/state.ts"],"names":[],"mappings":"AACA,OAAO,MAAqB,MAAM,oBAAoB,CAAC;AAevD,eAAO,MAAM,KAAK,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,UAAU,CAAC,OAAO,MAAM,CAkB7D,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"tailwind.plugin.d.ts","sourceRoot":"","sources":["../../../../packages/tailwind/src/tailwind.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AAUxC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAE/E,UAAU,qBAAqB;IAE7B,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/C,aAAa,CAAC,EAAE,MAAM,CAAC;CAExB;AAED,qBAAa,cAAe,SAAQ,cAAc,CAChD,kBAAkB,EAClB,qBAAqB,CACtB;IACQ,YAAY,wBAAgB;IAC5B,IAAI,SAAc;IACzB,WAAW,4BAAsB;CAClC;AAED,cAAM,kBAAmB,SAAQ,kBAAkB,CAAC,qBAAqB,CAAC;IACxE,MAAM;IAMN,IAAI,IAAI,UAAU,CAAC,OAAO,MAAM,CAAC,WAAW,CAAC;CAwF9C"}
File without changes
File without changes
File without changes