@akin2unde/flowui-core 0.1.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/dist/index.js ADDED
@@ -0,0 +1,473 @@
1
+ // src/theme.ts
2
+ var scale = (values) => ({
3
+ 50: values[0],
4
+ 100: values[1],
5
+ 200: values[2],
6
+ 300: values[3],
7
+ 400: values[4],
8
+ 500: values[5],
9
+ 600: values[6],
10
+ 700: values[7],
11
+ 800: values[8],
12
+ 900: values[9],
13
+ 950: values[10]
14
+ });
15
+ var defaultTheme = {
16
+ palette: {
17
+ primary: scale([
18
+ "#eff6ff",
19
+ "#dbeafe",
20
+ "#bfdbfe",
21
+ "#93c5fd",
22
+ "#60a5fa",
23
+ "#3b82f6",
24
+ "#2563eb",
25
+ "#1d4ed8",
26
+ "#1e40af",
27
+ "#1e3a8a",
28
+ "#172554"
29
+ ]),
30
+ secondary: scale([
31
+ "#f8fafc",
32
+ "#f1f5f9",
33
+ "#e2e8f0",
34
+ "#cbd5e1",
35
+ "#94a3b8",
36
+ "#64748b",
37
+ "#475569",
38
+ "#334155",
39
+ "#1e293b",
40
+ "#0f172a",
41
+ "#020617"
42
+ ]),
43
+ success: scale([
44
+ "#f0fdf4",
45
+ "#dcfce7",
46
+ "#bbf7d0",
47
+ "#86efac",
48
+ "#4ade80",
49
+ "#22c55e",
50
+ "#16a34a",
51
+ "#15803d",
52
+ "#166534",
53
+ "#14532d",
54
+ "#052e16"
55
+ ]),
56
+ danger: scale([
57
+ "#fef2f2",
58
+ "#fee2e2",
59
+ "#fecaca",
60
+ "#fca5a5",
61
+ "#f87171",
62
+ "#ef4444",
63
+ "#dc2626",
64
+ "#b91c1c",
65
+ "#991b1b",
66
+ "#7f1d1d",
67
+ "#450a0a"
68
+ ]),
69
+ warning: scale([
70
+ "#fffbeb",
71
+ "#fef3c7",
72
+ "#fde68a",
73
+ "#fcd34d",
74
+ "#fbbf24",
75
+ "#f59e0b",
76
+ "#d97706",
77
+ "#b45309",
78
+ "#92400e",
79
+ "#78350f",
80
+ "#451a03"
81
+ ]),
82
+ info: scale([
83
+ "#ecfeff",
84
+ "#cffafe",
85
+ "#a5f3fc",
86
+ "#67e8f9",
87
+ "#22d3ee",
88
+ "#06b6d4",
89
+ "#0891b2",
90
+ "#0e7490",
91
+ "#155e75",
92
+ "#164e63",
93
+ "#083344"
94
+ ]),
95
+ neutral: scale([
96
+ "#fafafa",
97
+ "#f5f5f5",
98
+ "#e5e5e5",
99
+ "#d4d4d4",
100
+ "#a3a3a3",
101
+ "#737373",
102
+ "#525252",
103
+ "#404040",
104
+ "#262626",
105
+ "#171717",
106
+ "#0a0a0a"
107
+ ])
108
+ },
109
+ schemes: {
110
+ light: {
111
+ canvas: "#f8fafc",
112
+ surface: "#ffffff",
113
+ surfaceRaised: "#ffffff",
114
+ surfaceSunken: "#f1f5f9",
115
+ text: "#0f172a",
116
+ textMuted: "#64748b",
117
+ textDisabled: "#94a3b8",
118
+ textInverse: "#ffffff",
119
+ border: "#e2e8f0",
120
+ borderStrong: "#94a3b8",
121
+ focus: "#2563eb",
122
+ overlay: "rgba(15,23,42,.55)"
123
+ },
124
+ dark: {
125
+ canvas: "#020617",
126
+ surface: "#0f172a",
127
+ surfaceRaised: "#1e293b",
128
+ surfaceSunken: "#020617",
129
+ text: "#f8fafc",
130
+ textMuted: "#94a3b8",
131
+ textDisabled: "#64748b",
132
+ textInverse: "#0f172a",
133
+ border: "#334155",
134
+ borderStrong: "#64748b",
135
+ focus: "#60a5fa",
136
+ overlay: "rgba(0,0,0,.72)"
137
+ }
138
+ },
139
+ spacing: {
140
+ none: 0,
141
+ xs: ".25rem",
142
+ sm: ".5rem",
143
+ md: "1rem",
144
+ lg: "1.5rem",
145
+ xl: "2rem",
146
+ "2xl": "3rem",
147
+ "3xl": "4rem"
148
+ },
149
+ radius: {
150
+ none: 0,
151
+ xs: ".125rem",
152
+ sm: ".25rem",
153
+ md: ".5rem",
154
+ lg: ".75rem",
155
+ xl: "1rem",
156
+ full: "9999px"
157
+ },
158
+ fontSize: {
159
+ xs: ".75rem",
160
+ sm: ".875rem",
161
+ md: "1rem",
162
+ lg: "1.125rem",
163
+ xl: "1.25rem",
164
+ "2xl": "1.5rem",
165
+ "3xl": "1.875rem"
166
+ },
167
+ fontWeight: {
168
+ thin: 100,
169
+ extraLight: 200,
170
+ light: 300,
171
+ normal: 400,
172
+ medium: 500,
173
+ semiBold: 600,
174
+ bold: 700,
175
+ extraBold: 800,
176
+ black: 900
177
+ },
178
+ shadows: {
179
+ none: "none",
180
+ xs: "0 1px 2px rgb(15 23 42 / .05)",
181
+ sm: "0 1px 3px rgb(15 23 42 / .12)",
182
+ md: "0 4px 8px rgb(15 23 42 / .14)",
183
+ lg: "0 10px 20px rgb(15 23 42 / .16)",
184
+ xl: "0 20px 35px rgb(15 23 42 / .20)"
185
+ },
186
+ breakpoints: {
187
+ sm: "40rem",
188
+ md: "48rem",
189
+ lg: "64rem",
190
+ xl: "80rem",
191
+ xxl: "96rem"
192
+ },
193
+ zIndex: {
194
+ base: 0,
195
+ sticky: 100,
196
+ dropdown: 1e3,
197
+ overlay: 1100,
198
+ dialog: 1200,
199
+ popover: 1300,
200
+ tooltip: 1400,
201
+ notification: 1500
202
+ }
203
+ };
204
+ function merge(base, override) {
205
+ if (!override) return structuredClone(base);
206
+ const result = structuredClone(base);
207
+ for (const [key, value] of Object.entries(override)) {
208
+ if (value === void 0) continue;
209
+ const current = result[key];
210
+ result[key] = typeof value === "object" && value !== null && !Array.isArray(value) && typeof current === "object" && current !== null ? merge(current, value) : value;
211
+ }
212
+ return result;
213
+ }
214
+ var createTheme = (override) => merge(defaultTheme, override);
215
+ var vars = (prefix, object) => Object.entries(object).flatMap(
216
+ ([key, value]) => typeof value === "object" && value !== null ? vars(`${prefix}-${key}`, value) : [`--fui-${prefix}-${key}: ${String(value)};`]
217
+ );
218
+ function themeToCSS(theme, mode = "system") {
219
+ const shared = [
220
+ ...vars("palette", theme.palette),
221
+ ...vars("spacing", theme.spacing),
222
+ ...vars("radius", theme.radius),
223
+ ...vars("font-size", theme.fontSize),
224
+ ...vars("font-weight", theme.fontWeight),
225
+ ...vars("shadow", theme.shadows),
226
+ ...vars("z", theme.zIndex)
227
+ ];
228
+ const scheme = (name) => Object.entries(theme.schemes[name]).map(
229
+ ([key, value]) => `--fui-color-${key}: ${value};`
230
+ );
231
+ const active = mode === "dark" ? scheme("dark") : scheme("light");
232
+ const system = mode === "system" ? `@media (prefers-color-scheme: dark){[data-fui-theme="system"]{${scheme("dark").join("")}}}` : "";
233
+ return `[data-fui-theme="${mode}"]{${shared.join("")}${active.join("")}}${system}${responsiveCSS(theme)}`;
234
+ }
235
+ var responsiveProperties = {
236
+ width: "width",
237
+ minWidth: "min-width",
238
+ maxWidth: "max-width",
239
+ height: "height",
240
+ minHeight: "min-height",
241
+ maxHeight: "max-height",
242
+ display: "display",
243
+ overflow: "overflow",
244
+ overflowX: "overflow-x",
245
+ overflowY: "overflow-y",
246
+ positionType: "position",
247
+ absolute: "position",
248
+ top: "top",
249
+ right: "right",
250
+ bottom: "bottom",
251
+ left: "left",
252
+ zIndex: "z-index",
253
+ flex: "flex",
254
+ flexGrow: "flex-grow",
255
+ flexShrink: "flex-shrink",
256
+ flexBasis: "flex-basis",
257
+ selfAlign: "align-self",
258
+ order: "order",
259
+ direction: "flex-direction",
260
+ wrap: "flex-wrap",
261
+ justify: "justify-content",
262
+ align: "align-items",
263
+ gap: "gap",
264
+ rowGap: "row-gap",
265
+ columnGap: "column-gap",
266
+ margin: "margin",
267
+ marginX: "margin-inline",
268
+ marginY: "margin-block",
269
+ marginTop: "margin-top",
270
+ marginRight: "margin-right",
271
+ marginBottom: "margin-bottom",
272
+ marginLeft: "margin-left",
273
+ padding: "padding",
274
+ paddingX: "padding-inline",
275
+ paddingY: "padding-block",
276
+ paddingTop: "padding-top",
277
+ paddingRight: "padding-right",
278
+ paddingBottom: "padding-bottom",
279
+ paddingLeft: "padding-left",
280
+ borderWidth: "border-width",
281
+ borderStyle: "border-style",
282
+ borderColor: "border-color",
283
+ cornerRadius: "border-radius",
284
+ backgroundColor: "background-color",
285
+ opacity: "opacity",
286
+ shadow: "box-shadow",
287
+ textColor: "color",
288
+ fontFamily: "font-family",
289
+ fontSize: "font-size",
290
+ fontWeight: "font-weight",
291
+ textAlign: "text-align",
292
+ textTransform: "text-transform"
293
+ };
294
+ function responsiveCSS(theme) {
295
+ const output = [];
296
+ for (const [prop, css] of Object.entries(responsiveProperties)) {
297
+ output.push(`.fui-r-${prop}-default{${css}:var(--fui-${prop}-default)}`);
298
+ for (const [breakpoint, width] of Object.entries(theme.breakpoints)) {
299
+ output.push(
300
+ `@media(min-width:${width}){.fui-r-${prop}-${breakpoint}{${css}:var(--fui-${prop}-${breakpoint})}}`
301
+ );
302
+ }
303
+ }
304
+ return output.join("");
305
+ }
306
+
307
+ // src/style.ts
308
+ var breakpoints = ["default", "sm", "md", "lg", "xl", "xxl"];
309
+ var isResponsive = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
310
+ var length = (value) => typeof value === "number" ? value === 0 ? 0 : `${value}px` : value;
311
+ var dimension = (value) => ({
312
+ full: "100%",
313
+ fit: "fit-content",
314
+ min: "min-content",
315
+ max: "max-content"
316
+ })[String(value)] ?? length(value);
317
+ var spacing = (value, theme) => value in theme.spacing ? `var(--fui-spacing-${String(value)})` : length(value);
318
+ var color = (value) => {
319
+ if ([
320
+ "canvas",
321
+ "surface",
322
+ "surfaceRaised",
323
+ "surfaceSunken",
324
+ "text",
325
+ "textMuted",
326
+ "textDisabled",
327
+ "textInverse",
328
+ "border",
329
+ "borderStrong",
330
+ "focus",
331
+ "overlay"
332
+ ].includes(value))
333
+ return `var(--fui-color-${value})`;
334
+ if (/^(primary|secondary|success|danger|warning|info|neutral)(\.\d+)?$/.test(
335
+ value
336
+ )) {
337
+ const [name, shade = "600"] = value.split(".");
338
+ return `var(--fui-palette-${name}-${shade})`;
339
+ }
340
+ return value;
341
+ };
342
+ var justify = (value) => ({
343
+ start: "flex-start",
344
+ end: "flex-end",
345
+ between: "space-between",
346
+ around: "space-around",
347
+ evenly: "space-evenly"
348
+ })[String(value)] ?? String(value);
349
+ var align = (value) => ({ start: "flex-start", end: "flex-end" })[String(value)] ?? String(value);
350
+ var propertyMap = {
351
+ width: { css: "width", resolve: dimension },
352
+ minWidth: { css: "minWidth", resolve: dimension },
353
+ maxWidth: { css: "maxWidth", resolve: dimension },
354
+ height: { css: "height", resolve: dimension },
355
+ minHeight: { css: "minHeight", resolve: dimension },
356
+ maxHeight: { css: "maxHeight", resolve: dimension },
357
+ display: { css: "display", resolve: String },
358
+ overflow: { css: "overflow", resolve: String },
359
+ overflowX: { css: "overflowX", resolve: String },
360
+ overflowY: { css: "overflowY", resolve: String },
361
+ positionType: { css: "position", resolve: String },
362
+ absolute: {
363
+ css: "position",
364
+ resolve: ((value) => value ? "absolute" : "static")
365
+ },
366
+ top: { css: "top", resolve: length },
367
+ right: { css: "right", resolve: length },
368
+ bottom: { css: "bottom", resolve: length },
369
+ left: { css: "left", resolve: length },
370
+ zIndex: { css: "zIndex", resolve: String },
371
+ flex: { css: "flex", resolve: String },
372
+ flexGrow: { css: "flexGrow", resolve: String },
373
+ flexShrink: { css: "flexShrink", resolve: String },
374
+ flexBasis: { css: "flexBasis", resolve: dimension },
375
+ selfAlign: { css: "alignSelf", resolve: align },
376
+ order: { css: "order", resolve: String },
377
+ direction: { css: "flexDirection", resolve: String },
378
+ wrap: { css: "flexWrap", resolve: String },
379
+ justify: { css: "justifyContent", resolve: justify },
380
+ align: { css: "alignItems", resolve: align },
381
+ gap: { css: "gap", resolve: spacing },
382
+ rowGap: { css: "rowGap", resolve: spacing },
383
+ columnGap: { css: "columnGap", resolve: spacing },
384
+ margin: { css: "margin", resolve: spacing },
385
+ marginX: { css: "marginInline", resolve: spacing },
386
+ marginY: { css: "marginBlock", resolve: spacing },
387
+ marginTop: { css: "marginTop", resolve: spacing },
388
+ marginRight: { css: "marginRight", resolve: spacing },
389
+ marginBottom: { css: "marginBottom", resolve: spacing },
390
+ marginLeft: { css: "marginLeft", resolve: spacing },
391
+ padding: { css: "padding", resolve: spacing },
392
+ paddingX: { css: "paddingInline", resolve: spacing },
393
+ paddingY: { css: "paddingBlock", resolve: spacing },
394
+ paddingTop: { css: "paddingTop", resolve: spacing },
395
+ paddingRight: { css: "paddingRight", resolve: spacing },
396
+ paddingBottom: { css: "paddingBottom", resolve: spacing },
397
+ paddingLeft: { css: "paddingLeft", resolve: spacing },
398
+ borderWidth: { css: "borderWidth", resolve: length },
399
+ borderStyle: { css: "borderStyle", resolve: String },
400
+ borderColor: { css: "borderColor", resolve: color },
401
+ cornerRadius: {
402
+ css: "borderRadius",
403
+ resolve: ((v, t) => v in t.radius ? `var(--fui-radius-${v})` : length(v))
404
+ },
405
+ backgroundColor: { css: "backgroundColor", resolve: color },
406
+ opacity: { css: "opacity", resolve: String },
407
+ shadow: {
408
+ css: "boxShadow",
409
+ resolve: ((v) => `var(--fui-shadow-${v})`)
410
+ },
411
+ textColor: { css: "color", resolve: color },
412
+ fontFamily: { css: "fontFamily", resolve: String },
413
+ fontSize: {
414
+ css: "fontSize",
415
+ resolve: ((v, t) => v in t.fontSize ? `var(--fui-font-size-${v})` : length(v))
416
+ },
417
+ fontWeight: {
418
+ css: "fontWeight",
419
+ resolve: ((v, t) => v in t.fontWeight ? `var(--fui-font-weight-${v})` : v)
420
+ },
421
+ textAlign: { css: "textAlign", resolve: String },
422
+ textTransform: {
423
+ css: "textTransform",
424
+ resolve: String
425
+ }
426
+ };
427
+ function resolveFlowStyle(props, theme) {
428
+ const userStyle = props.style;
429
+ const style = {};
430
+ const classNames = [];
431
+ for (const [prop, definition] of Object.entries(propertyMap)) {
432
+ const value = props[prop];
433
+ if (value === void 0) continue;
434
+ if (!isResponsive(value)) {
435
+ style[definition.css] = definition.resolve(
436
+ value,
437
+ theme
438
+ );
439
+ continue;
440
+ }
441
+ for (const point of breakpoints) {
442
+ const pointValue = value[point];
443
+ if (pointValue === void 0) continue;
444
+ classNames.push(`fui-r-${prop}-${point}`);
445
+ style[`--fui-${prop}-${point}`] = definition.resolve(pointValue, theme);
446
+ }
447
+ }
448
+ const lines = props.lines;
449
+ if (typeof lines === "number" && lines > 0) {
450
+ style.overflow = "hidden";
451
+ style.display = "-webkit-box";
452
+ style.WebkitBoxOrient = "vertical";
453
+ style.WebkitLineClamp = lines;
454
+ }
455
+ Object.assign(style, userStyle);
456
+ return { classNames, style };
457
+ }
458
+ function flowClass(base, props, resolution, ...extra) {
459
+ return [
460
+ base,
461
+ ...extra.filter(Boolean),
462
+ ...resolution.classNames,
463
+ props.className
464
+ ].filter(Boolean).join(" ");
465
+ }
466
+ export {
467
+ createTheme,
468
+ defaultTheme,
469
+ flowClass,
470
+ resolveFlowStyle,
471
+ responsiveCSS,
472
+ themeToCSS
473
+ };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@akin2unde/flowui-core",
3
+ "version": "0.1.0",
4
+ "description": "Framework-independent contracts, themes and style resolution for FlowUI.",
5
+ "author": "Akintunde Morakinyo",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/akin2unde/FlowUI.git",
9
+ "directory": "packages/core"
10
+ },
11
+ "homepage": "https://github.com/akin2unde/FlowUI#readme",
12
+ "bugs": "https://github.com/akin2unde/FlowUI/issues",
13
+ "keywords": [
14
+ "flowui",
15
+ "ui",
16
+ "tailwind",
17
+ "typescript"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "type": "module",
23
+ "main": "./dist/index.cjs",
24
+ "module": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js",
30
+ "require": "./dist/index.cjs"
31
+ }
32
+ },
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "scripts": {
37
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean",
38
+ "typecheck": "tsc --noEmit",
39
+ "test": "vitest run"
40
+ },
41
+ "dependencies": {
42
+ "csstype": "^3.1.3"
43
+ },
44
+ "devDependencies": {
45
+ "tsup": "^8.5.0",
46
+ "typescript": "^5.9.0",
47
+ "vitest": "^3.2.0"
48
+ },
49
+ "sideEffects": false
50
+ }