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