@melcanz85/chaincss 1.9.5 → 1.10.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/package.json CHANGED
@@ -1,31 +1,42 @@
1
1
  {
2
2
  "name": "@melcanz85/chaincss",
3
- "version": "1.9.5",
3
+ "version": "1.10.0",
4
4
  "description": "A simple package transpiler for js to css",
5
- "main": "index.js",
6
- "module": "index.react.js",
7
5
  "exports": {
8
6
  ".": {
9
- "require": "./index.js",
10
- "import": "./index.react.js"
7
+ "types": "./types.d.ts",
8
+ "node": {
9
+ "require": "./node/index.js"
10
+ },
11
+ "browser": {
12
+ "import": "./browser/index.js"
13
+ },
14
+ "default": "./browser/index.js"
15
+ },
16
+ "./node": {
17
+ "types": "./types.d.ts",
18
+ "require": "./node/index.js"
19
+ },
20
+ "./browser": {
21
+ "types": "./types.d.ts",
22
+ "import": "./browser/index.js"
11
23
  },
12
24
  "./react": {
13
- "import": "./index.react.js"
25
+ "types": "./types.d.ts",
26
+ "browser": {
27
+ "import": "./browser/index.js"
28
+ },
29
+ "default": "./browser/index.js"
14
30
  }
15
31
  },
16
32
  "types": "types.d.ts",
17
33
  "files": [
18
- "index.js",
19
- "index.react.js",
20
- "chaincss.js",
21
- "transpiler.js",
22
- "tokens.js",
23
- "react-hooks.js",
24
- "strVal.js",
25
- "atomic-optimizer.js",
26
- "cache-manager.js",
27
- "prefixer.js",
28
- "types.d.ts"
34
+ "node/",
35
+ "browser/",
36
+ "shared/",
37
+ "types.d.ts",
38
+ "README.md",
39
+ "LICENSE"
29
40
  ],
30
41
  "publishConfig": {
31
42
  "access": "public",
@@ -37,7 +48,7 @@
37
48
  },
38
49
  "homepage": "https://melcanz08.github.io/chaincss-website",
39
50
  "bin": {
40
- "chaincss": "chaincss.js"
51
+ "chaincss": "./node/chaincss.js"
41
52
  },
42
53
  "dependencies": {
43
54
  "chokidar": "^3.5.3",
@@ -68,7 +79,9 @@
68
79
  "css",
69
80
  "js",
70
81
  "transpiler",
71
- "compiler"
82
+ "compiler",
83
+ "css-in-js",
84
+ "react"
72
85
  ],
73
86
  "author": "Rommel Caneos",
74
87
  "license": "MIT"
@@ -0,0 +1,256 @@
1
+ class DesignTokens {
2
+ constructor(tokens = {}) {
3
+ this.tokens = this.deepFreeze({
4
+ colors: {},
5
+ spacing: {},
6
+ typography: {},
7
+ breakpoints: {},
8
+ zIndex: {},
9
+ shadows: {},
10
+ borderRadius: {},
11
+ ...tokens
12
+ });
13
+
14
+ this.flattened = this.flattenTokens(this.tokens);
15
+ }
16
+
17
+ // Deep freeze to prevent accidental modifications
18
+ deepFreeze(obj) {
19
+ Object.keys(obj).forEach(key => {
20
+ if (typeof obj[key] === 'object' && obj[key] !== null) {
21
+ this.deepFreeze(obj[key]);
22
+ }
23
+ });
24
+ return Object.freeze(obj);
25
+ }
26
+
27
+ // Flatten nested tokens for easy access
28
+ flattenTokens(obj, prefix = '') {
29
+ return Object.keys(obj).reduce((acc, key) => {
30
+ const prefixed = prefix ? `${prefix}.${key}` : key;
31
+
32
+ if (typeof obj[key] === 'object' && obj[key] !== null) {
33
+ Object.assign(acc, this.flattenTokens(obj[key], prefixed));
34
+ } else {
35
+ acc[prefixed] = obj[key];
36
+ }
37
+
38
+ return acc;
39
+ }, {});
40
+ }
41
+
42
+ // Get token value by path (e.g., 'colors.primary')
43
+ get(path, defaultValue = '') {
44
+ return this.flattened[path] || defaultValue;
45
+ }
46
+
47
+ // Generate CSS variables from tokens
48
+ toCSSVariables(prefix = 'chain') {
49
+ let css = ':root {\n';
50
+
51
+ Object.entries(this.flattened).forEach(([key, value]) => {
52
+ const varName = `--${prefix}-${key.replace(/\./g, '-')}`;
53
+ css += ` ${varName}: ${value};\n`;
54
+ });
55
+
56
+ css += '}\n';
57
+ return css;
58
+ }
59
+
60
+ // Create a theme variant
61
+ createTheme(name, overrides) {
62
+ const themeTokens = { ...this.flattened };
63
+
64
+ Object.entries(overrides).forEach(([key, value]) => {
65
+ if (themeTokens[key]) {
66
+ themeTokens[key] = value;
67
+ }
68
+ });
69
+
70
+ return new DesignTokens(this.expandTokens(themeTokens));
71
+ }
72
+
73
+ // Expand flattened tokens back to nested structure
74
+ expandTokens(flattened) {
75
+ const result = {};
76
+
77
+ Object.entries(flattened).forEach(([key, value]) => {
78
+ const parts = key.split('.');
79
+ let current = result;
80
+
81
+ for (let i = 0; i < parts.length - 1; i++) {
82
+ current[parts[i]] = current[parts[i]] || {};
83
+ current = current[parts[i]];
84
+ }
85
+
86
+ current[parts[parts.length - 1]] = value;
87
+ });
88
+
89
+ return result;
90
+ }
91
+ }
92
+
93
+ // Default tokens
94
+ const defaultTokens = {
95
+ colors: {
96
+ primary: '#667eea',
97
+ secondary: '#764ba2',
98
+ success: '#48bb78',
99
+ danger: '#f56565',
100
+ warning: '#ed8936',
101
+ info: '#4299e1',
102
+ light: '#f7fafc',
103
+ dark: '#1a202c',
104
+ white: '#ffffff',
105
+ black: '#000000',
106
+ gray: {
107
+ 100: '#f7fafc',
108
+ 200: '#edf2f7',
109
+ 300: '#e2e8f0',
110
+ 400: '#cbd5e0',
111
+ 500: '#a0aec0',
112
+ 600: '#718096',
113
+ 700: '#4a5568',
114
+ 800: '#2d3748',
115
+ 900: '#1a202c'
116
+ }
117
+ },
118
+
119
+ spacing: {
120
+ 0: '0',
121
+ 1: '0.25rem',
122
+ 2: '0.5rem',
123
+ 3: '0.75rem',
124
+ 4: '1rem',
125
+ 5: '1.25rem',
126
+ 6: '1.5rem',
127
+ 8: '2rem',
128
+ 10: '2.5rem',
129
+ 12: '3rem',
130
+ 16: '4rem',
131
+ 20: '5rem',
132
+ 24: '6rem',
133
+ 32: '8rem',
134
+ 40: '10rem',
135
+ 48: '12rem',
136
+ 56: '14rem',
137
+ 64: '16rem',
138
+ xs: '0.5rem',
139
+ sm: '1rem',
140
+ md: '1.5rem',
141
+ lg: '2rem',
142
+ xl: '3rem',
143
+ '2xl': '4rem',
144
+ '3xl': '6rem'
145
+ },
146
+
147
+ typography: {
148
+ fontFamily: {
149
+ sans: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
150
+ serif: 'Georgia, Cambria, "Times New Roman", Times, serif',
151
+ mono: 'SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace'
152
+ },
153
+ fontSize: {
154
+ xs: '0.75rem',
155
+ sm: '0.875rem',
156
+ base: '1rem',
157
+ lg: '1.125rem',
158
+ xl: '1.25rem',
159
+ '2xl': '1.5rem',
160
+ '3xl': '1.875rem',
161
+ '4xl': '2.25rem',
162
+ '5xl': '3rem'
163
+ },
164
+ fontWeight: {
165
+ hairline: '100',
166
+ thin: '200',
167
+ light: '300',
168
+ normal: '400',
169
+ medium: '500',
170
+ semibold: '600',
171
+ bold: '700',
172
+ extrabold: '800',
173
+ black: '900'
174
+ },
175
+ lineHeight: {
176
+ none: '1',
177
+ tight: '1.25',
178
+ snug: '1.375',
179
+ normal: '1.5',
180
+ relaxed: '1.625',
181
+ loose: '2'
182
+ }
183
+ },
184
+
185
+ breakpoints: {
186
+ sm: '640px',
187
+ md: '768px',
188
+ lg: '1024px',
189
+ xl: '1280px',
190
+ '2xl': '1536px'
191
+ },
192
+
193
+ zIndex: {
194
+ 0: '0',
195
+ 10: '10',
196
+ 20: '20',
197
+ 30: '30',
198
+ 40: '40',
199
+ 50: '50',
200
+ auto: 'auto',
201
+ dropdown: '1000',
202
+ sticky: '1020',
203
+ fixed: '1030',
204
+ modal: '1040',
205
+ popover: '1050',
206
+ tooltip: '1060'
207
+ },
208
+
209
+ shadows: {
210
+ sm: '0 1px 2px 0 rgba(0, 0, 0, 0.05)',
211
+ base: '0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)',
212
+ md: '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
213
+ lg: '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',
214
+ xl: '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)',
215
+ '2xl': '0 25px 50px -12px rgba(0, 0, 0, 0.25)',
216
+ inner: 'inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)',
217
+ none: 'none'
218
+ },
219
+
220
+ borderRadius: {
221
+ none: '0',
222
+ sm: '0.125rem',
223
+ base: '0.25rem',
224
+ md: '0.375rem',
225
+ lg: '0.5rem',
226
+ xl: '0.75rem',
227
+ '2xl': '1rem',
228
+ '3xl': '1.5rem',
229
+ full: '9999px'
230
+ }
231
+ };
232
+
233
+ // Create and export tokens instance
234
+ const tokens = new DesignTokens(defaultTokens);
235
+
236
+ // Token utility functions
237
+ const createTokens = (customTokens) => {
238
+ return new DesignTokens(customTokens);
239
+ };
240
+
241
+ // Generate responsive values
242
+ const responsive = (values) => {
243
+ if (typeof values === 'string') return values;
244
+
245
+ return Object.entries(values).map(([breakpoint, value]) => {
246
+ if (breakpoint === 'base') return value;
247
+ return `@media (min-width: ${tokens.get(`breakpoints.${breakpoint}`)}) { ${value} }`;
248
+ }).join(' ');
249
+ };
250
+
251
+ export {
252
+ tokens,
253
+ createTokens,
254
+ responsive,
255
+ DesignTokens
256
+ };
package/types.d.ts CHANGED
@@ -7,6 +7,9 @@ declare module '@melcanz85/chaincss' {
7
7
  [cssProperty: string]: any;
8
8
  }
9
9
 
10
+ export const createTokens: any;
11
+ export const responsive: any;
12
+
10
13
  // Base interface for CSS properties (dynamic)
11
14
  export interface CSSPropertyBuilder {
12
15
  [key: string]: (value: string | number) => ChainBuilder;
package/index.js DELETED
@@ -1,24 +0,0 @@
1
- const { $, run, compile, chain, tokens, createTokens } = require('./transpiler');
2
- const { processor, watch } = require('./chaincss');
3
-
4
- // Conditionally export React hooks if in React environment
5
- let reactHooks = {};
6
- try {
7
- // Check if React is available
8
- require.resolve('react');
9
- reactHooks = require('./react-hooks');
10
- } catch {
11
-
12
- }
13
-
14
- module.exports = {
15
- $,
16
- run,
17
- compile,
18
- processor,
19
- watch,
20
- chain,
21
- tokens,
22
- createTokens,
23
- ...reactHooks
24
- };
package/index.react.js DELETED
@@ -1,4 +0,0 @@
1
- export * from './react-hooks';
2
-
3
- // Re-export core for convenience
4
- export { $, tokens, createTokens } from './transpiler';
File without changes
File without changes
File without changes