@akin2unde/flowui-core 1.0.2 → 1.0.4

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.cjs CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  AsyncLabelStore: () => AsyncLabelStore,
24
+ buildChart: () => buildChart,
24
25
  clampNumber: () => clampNumber,
25
26
  createAsyncLabelStore: () => createAsyncLabelStore,
26
27
  createNotificationTimer: () => createNotificationTimer,
@@ -44,7 +45,9 @@ __export(index_exports, {
44
45
  selectedTreeModels: () => selectedTreeModels,
45
46
  setLocalDayBoundary: () => setLocalDayBoundary,
46
47
  tableToCsv: () => tableToCsv,
47
- themeToCSS: () => themeToCSS
48
+ themeToCSS: () => themeToCSS,
49
+ toggleTreeCheck: () => toggleTreeCheck,
50
+ treeCheckState: () => treeCheckState
48
51
  });
49
52
  module.exports = __toCommonJS(index_exports);
50
53
 
@@ -727,6 +730,22 @@ function selectedTreeModels(nodes, values) {
727
730
  const selected = new Set(values);
728
731
  return flattenTree(nodes).filter((node) => selected.has(node.value));
729
732
  }
733
+ function treeCheckState(node, selected) {
734
+ const leaves = enabledSelectableDescendants(node);
735
+ const checked = leaves.filter((leaf) => selected.has(leaf.value)).length;
736
+ if (!checked) return false;
737
+ return checked === leaves.length ? true : "mixed";
738
+ }
739
+ function toggleTreeCheck(node, values) {
740
+ const selected = new Set(values);
741
+ if (node.disabled || node.selectable === false) return [...selected];
742
+ const remove = treeCheckState(node, selected) === true;
743
+ for (const leaf of enabledSelectableDescendants(node)) {
744
+ if (remove) selected.delete(leaf.value);
745
+ else selected.add(leaf.value);
746
+ }
747
+ return [...selected];
748
+ }
730
749
 
731
750
  // src/async-label.ts
732
751
  var idle = Object.freeze({ status: "idle" });
@@ -1081,9 +1100,151 @@ function createNotificationTimer(duration, onElapsed) {
1081
1100
  }
1082
1101
  };
1083
1102
  }
1103
+
1104
+ // src/chart.ts
1105
+ var palette = ["#3b82c4", "#f59429", "#8cba39", "#ed74a7", "#8762c8"];
1106
+ function buildChart(data, type, height, showValues) {
1107
+ const width = 640;
1108
+ const marks = [];
1109
+ const labels = [];
1110
+ const label = (x2, y2, text, anchor = "middle") => labels.push({ x: x2, y: y2, text: String(text), anchor });
1111
+ const legend = data.series.map((series, index) => ({
1112
+ label: series.name,
1113
+ color: series.color ? resolveColorValue(series.color) : palette[index % palette.length]
1114
+ }));
1115
+ const colorAt = (index) => palette[index % palette.length];
1116
+ const path = (d, fill = "none", stroke, opacity) => marks.push({ path: d, fill, stroke, opacity });
1117
+ if (type === "pie" || type === "doughnut") {
1118
+ const values2 = (data.series[0]?.data ?? []).map(
1119
+ (value) => Math.max(0, value)
1120
+ );
1121
+ const total = values2.reduce((sum, value) => sum + value, 0);
1122
+ const radius = height * 0.38;
1123
+ const centerX = width / 2;
1124
+ const centerY = height / 2;
1125
+ const point = (r, angle) => [
1126
+ centerX + r * Math.cos(angle),
1127
+ centerY + r * Math.sin(angle)
1128
+ ];
1129
+ let start = -Math.PI / 2;
1130
+ values2.forEach((value, index) => {
1131
+ if (!value || !total) return;
1132
+ const sweep = 2 * Math.PI * value / total;
1133
+ const end = start + Math.min(sweep, 2 * Math.PI - 1e-4);
1134
+ const inner = type === "doughnut" ? radius * 0.55 : 0;
1135
+ const large = sweep > Math.PI ? 1 : 0;
1136
+ const tail = inner ? `L ${point(inner, end)} A ${inner},${inner} 0 ${large} 0 ${point(inner, start)}` : `L ${centerX},${centerY}`;
1137
+ path(
1138
+ `M ${point(radius, start)} A ${radius},${radius} 0 ${large} 1 ${point(radius, end)} ${tail} Z`,
1139
+ colorAt(index),
1140
+ "white"
1141
+ );
1142
+ if (showValues) {
1143
+ const [x2, y2] = point(radius * 0.75, (start + end) / 2);
1144
+ label(x2, y2, value);
1145
+ }
1146
+ start += sweep;
1147
+ });
1148
+ return {
1149
+ marks,
1150
+ labels,
1151
+ legend: values2.map((_, index) => ({
1152
+ label: data.labels[index] ?? String(index + 1),
1153
+ color: colorAt(index)
1154
+ })),
1155
+ width,
1156
+ height
1157
+ };
1158
+ }
1159
+ const left = type === "horizontal-bar" ? 120 : 48;
1160
+ const right = width - 28;
1161
+ const top = 24;
1162
+ const bottom = height - 34;
1163
+ const values = data.series.flatMap((series) => series.data);
1164
+ const min = Math.min(0, ...values);
1165
+ const max = Math.max(1, ...values);
1166
+ const groupCount = Math.max(
1167
+ 1,
1168
+ data.labels.length,
1169
+ ...data.series.map((series) => series.data.length)
1170
+ );
1171
+ const groupWidth = (right - left) / groupCount;
1172
+ const groupHeight = (bottom - top) / groupCount;
1173
+ const x = (index) => left + groupWidth * (index + 0.5);
1174
+ const y = (value) => bottom - (value - min) / (max - min) * (bottom - top);
1175
+ const scaleX = (value) => left + (value - min) / (max - min) * (right - left);
1176
+ const horizontal = type === "horizontal-bar";
1177
+ path(
1178
+ horizontal ? `M ${left} ${top} V ${bottom} H ${right} M ${scaleX(0)} ${top} V ${bottom}` : `M ${left} ${top} V ${y(0)} H ${right}`,
1179
+ "none",
1180
+ "#cbd5e1"
1181
+ );
1182
+ data.labels.forEach(
1183
+ (item, index) => horizontal ? label(left - 10, top + groupHeight * (index + 0.5) + 4, item, "end") : label(x(index), height - 10, item)
1184
+ );
1185
+ const isLine = (index) => type === "line" || type === "area" || type === "combo" && (data.series[index].type ?? (index === data.series.length - 1 ? "line" : "column")) === "line";
1186
+ const columns = data.series.filter((_, index) => !isLine(index));
1187
+ data.series.forEach((series, index) => {
1188
+ if (isLine(index)) return;
1189
+ const columnIndex = columns.indexOf(series);
1190
+ const size = (horizontal ? groupHeight : groupWidth) * 0.68 / columns.length;
1191
+ series.data.forEach((value, valueIndex) => {
1192
+ const fill = type === "bar" || series.color || columns.length > 1 ? legend[index].color : colorAt(valueIndex);
1193
+ if (horizontal) {
1194
+ const rowY = top + groupHeight * (valueIndex + 0.5) + (columnIndex - columns.length / 2) * size;
1195
+ marks.push({
1196
+ x: Math.min(scaleX(0), scaleX(value)),
1197
+ y: rowY,
1198
+ width: Math.abs(scaleX(value) - scaleX(0)),
1199
+ height: Math.max(1, size - 3),
1200
+ fill
1201
+ });
1202
+ if (showValues)
1203
+ label(
1204
+ scaleX(value) + (value < 0 ? -4 : 4),
1205
+ rowY + size / 2 + 4,
1206
+ value,
1207
+ value < 0 ? "end" : "start"
1208
+ );
1209
+ } else {
1210
+ const columnX = x(valueIndex) + (columnIndex - columns.length / 2) * size;
1211
+ marks.push({
1212
+ x: columnX,
1213
+ y: Math.min(y(0), y(value)),
1214
+ width: Math.max(1, size - 3),
1215
+ height: Math.abs(y(0) - y(value)),
1216
+ fill
1217
+ });
1218
+ if (showValues) label(columnX + size / 2, y(value) - 6, value);
1219
+ }
1220
+ });
1221
+ });
1222
+ data.series.forEach((series, index) => {
1223
+ if (!isLine(index) || !series.data.length) return;
1224
+ const coordinates = series.data.map(
1225
+ (value, valueIndex) => `${x(valueIndex)},${y(value)}`
1226
+ );
1227
+ const trace = `M ${coordinates.join(" L ")}`;
1228
+ if (type === "area") {
1229
+ path(
1230
+ `${trace} L ${x(coordinates.length - 1)},${y(0)} L ${x(0)},${y(0)} Z`,
1231
+ legend[index].color,
1232
+ void 0,
1233
+ 0.28
1234
+ );
1235
+ }
1236
+ path(trace, "none", legend[index].color);
1237
+ if (showValues)
1238
+ series.data.forEach(
1239
+ (value, valueIndex) => label(x(valueIndex), y(value) - 8, value)
1240
+ );
1241
+ });
1242
+ return { marks, labels, legend, width, height };
1243
+ }
1084
1244
  // Annotate the CommonJS export names for ESM import in node:
1085
1245
  0 && (module.exports = {
1086
1246
  AsyncLabelStore,
1247
+ buildChart,
1087
1248
  clampNumber,
1088
1249
  createAsyncLabelStore,
1089
1250
  createNotificationTimer,
@@ -1107,5 +1268,7 @@ function createNotificationTimer(duration, onElapsed) {
1107
1268
  selectedTreeModels,
1108
1269
  setLocalDayBoundary,
1109
1270
  tableToCsv,
1110
- themeToCSS
1271
+ themeToCSS,
1272
+ toggleTreeCheck,
1273
+ treeCheckState
1111
1274
  });
package/dist/index.d.cts CHANGED
@@ -279,6 +279,7 @@ interface DropdownModel {
279
279
  group?: string | number;
280
280
  }
281
281
  interface TreeModel extends DropdownModel {
282
+ icon?: string;
282
283
  children?: TreeModel[];
283
284
  selectable?: boolean;
284
285
  hasChildren?: boolean;
@@ -369,6 +370,8 @@ interface PasswordInputProps extends Omit<InputProps, "type"> {
369
370
  visible?: boolean;
370
371
  }
371
372
  interface TreeProps extends BaseUIProps {
373
+ showCheckboxes?: boolean;
374
+ checkedValues?: readonly (string | number)[];
372
375
  nodes: TreeModel[];
373
376
  value?: string | number;
374
377
  defaultExpanded?: boolean;
@@ -506,8 +509,9 @@ interface PhoneInputProps extends BaseUIProps, DisableableProps {
506
509
  placeholder?: string;
507
510
  name?: string;
508
511
  }
509
- type ChartType = "bar" | "line" | "pie" | "doughnut";
512
+ type ChartType = "bar" | "column" | "horizontal-bar" | "line" | "area" | "combo" | "pie" | "doughnut";
510
513
  interface ChartSeries {
514
+ type?: "column" | "line";
511
515
  name: string;
512
516
  data: number[];
513
517
  color?: ColorValue;
@@ -548,6 +552,8 @@ declare function flattenTree(nodes: TreeModel[]): TreeModel[];
548
552
  declare function enabledSelectableDescendants(node: TreeModel): TreeModel[];
549
553
  declare function filterTree(nodes: TreeModel[], query: string): TreeModel[];
550
554
  declare function selectedTreeModels(nodes: TreeModel[], values: SelectionValue[]): TreeModel[];
555
+ declare function treeCheckState(node: TreeModel, selected: ReadonlySet<SelectionValue>): boolean | "mixed";
556
+ declare function toggleTreeCheck(node: TreeModel, values: readonly SelectionValue[]): SelectionValue[];
551
557
 
552
558
  /** Code-to-text results. null is a confirmed missing value; absent keys are errors. */
553
559
  type LabelResults = Readonly<Record<string, string | null>>;
@@ -652,4 +658,94 @@ interface NotificationAction {
652
658
  onClick: () => void | Promise<void>;
653
659
  }
654
660
 
655
- export { type AlignValue, type AsyncLabelCode, type AsyncLabelConfig, type AsyncLabelOptions, type AsyncLabelState, AsyncLabelStore, type AutocompleteProps, type BadgeProps, type BaseUIProps, type BorderProps, type BreadcrumbItem, type BreadcrumbProps, type BreakpointName, type ButtonGroupProps, type ButtonProps, type CSSLength, type CSSVariableStyle, type CardProps, type CarouselProps, type ChartData, type ChartProps, type ChartSeries, type ChartType, type ColorPalette, type ColorScale, type ColorShade, type ColorValue, type ComponentSize, type ComponentVariant, type DateTimeMode, type DateTimeProps, type DeepPartial, type DialogPosition, type DimensionValue, type DisableableProps, type DividerProps, type DropdownBehaviorProps, type DropdownModel, type FieldFocusStyle, type FileUploadProps, type FlexContainerProps, type FlexDirection, type FlexItemProps, type FlexWrap, type FlowInputMode, type FlowUIStyle, type FlowUITheme, type FocusableProps, type HStackProps, type IconProps, type ImageProps, type InputProps, type JustifyValue, type KnobProps, type LabelLookup, type LabelProps, type LabelResolverContext, type LabelResults, type LayoutProps, type ListboxProps, type LoadingProps, type MenuItem, type MultiSelectProps, type NotificationAction, type NotificationHorizontal, type NotificationProps, type NotificationType, type NotificationVertical, type OTPInputProps, type Orientation, type PaletteColor, type PasswordInputProps, type PhoneCountry, type PhoneInputProps, type PhoneNumberValue, type PopoverProps, type PositionProps, type PositionValue, type RadiusToken, type RadiusValue, type RatingProps, type ReadOnlyProps, type RequiredProps, type ResolvedStyle, type ResponsiveObject, type ResponsiveValue, type SchemeColor, type SelectOption, type SelectionValue, type SliderProps, type SortDirection, type SortState, type SpacingProps, type SpacingToken, type SpacingValue, type StackProps, type StyleResolution, type SwitchProps, type TabItem, type TabSelectedStyle, type TableColumn, type TableLoadMoreContext, type ThemeColorScheme, type ThemeMode, type TimelineItem, type TimelineProps, type TooltipLocation, type TooltipProps, type TreeDropdownProps, type TreeModel, type TreeMultiSelectProps, type TreeProps, type TypographyProps, type VStackProps, type VisualProps, clampNumber, createAsyncLabelStore, createNotificationTimer, createTheme, defaultTheme, enabledSelectableDescendants, exportTableToCsv, exportTableToExcel, exportTableToPdf, filterTree, flattenTree, flowClass, formatLocalDateTime, notificationDuration, numericInputError, resolveColorValue, resolveFlowStyle, resolveTooltipLocation, responsiveCSS, sanitizeInputValue, selectedTreeModels, setLocalDayBoundary, tableToCsv, themeToCSS };
661
+ interface FlowTextStyle {
662
+ color?: string;
663
+ fontFamily?: string;
664
+ fontSize?: number;
665
+ fontWeight?: "normal" | "bold" | "400" | "500" | "600" | "700";
666
+ lineHeight?: number;
667
+ textAlign?: "left" | "center" | "right";
668
+ }
669
+ interface FlowIconStyle {
670
+ color?: string;
671
+ size?: number;
672
+ }
673
+ interface FlowAction {
674
+ Label: string;
675
+ Icon?: string;
676
+ IsReadonly?: boolean;
677
+ TextStyle?: FlowTextStyle;
678
+ IconStyle?: FlowIconStyle;
679
+ }
680
+ interface FlowStage {
681
+ Id: string;
682
+ Label: string;
683
+ IsCurrent?: boolean;
684
+ IsCompleted?: boolean;
685
+ IsDisabled?: boolean;
686
+ Actions?: readonly FlowAction[];
687
+ SelectedAction?: FlowAction;
688
+ TextStyle?: FlowTextStyle;
689
+ }
690
+ interface FlowStageStyle {
691
+ backgroundColor?: string;
692
+ icon?: string;
693
+ iconStyle?: FlowIconStyle;
694
+ textStyle?: FlowTextStyle;
695
+ }
696
+ interface FlowActionItemStyle {
697
+ backgroundColor?: string;
698
+ textStyle?: FlowTextStyle;
699
+ iconStyle?: FlowIconStyle;
700
+ }
701
+ interface WorkflowStepperProps extends BaseUIProps {
702
+ stages: readonly FlowStage[];
703
+ direction?: "horizontal" | "vertical";
704
+ labelPosition?: "above" | "below" | "beside";
705
+ lineColor?: string;
706
+ stageTextStyle?: FlowTextStyle;
707
+ completedStyle?: FlowStageStyle;
708
+ currentStyle?: FlowStageStyle;
709
+ disabledStyle?: FlowStageStyle;
710
+ actionMenuStyle?: {
711
+ backgroundColor?: string;
712
+ borderColor?: string;
713
+ borderRadius?: number;
714
+ boxShadow?: string;
715
+ };
716
+ actionItemStyle?: FlowActionItemStyle & {
717
+ hover?: FlowActionItemStyle;
718
+ selected?: FlowActionItemStyle;
719
+ readonly?: FlowActionItemStyle;
720
+ };
721
+ checkmarkStyle?: FlowIconStyle;
722
+ chevronStyle?: FlowIconStyle;
723
+ }
724
+
725
+ type Mark = {
726
+ fill: string;
727
+ path?: string;
728
+ stroke?: string;
729
+ opacity?: number;
730
+ x?: number;
731
+ y?: number;
732
+ width?: number;
733
+ height?: number;
734
+ };
735
+ declare function buildChart(data: ChartData, type: ChartType, height: number, showValues: boolean): {
736
+ marks: Mark[];
737
+ labels: {
738
+ x: number;
739
+ y: number;
740
+ text: string;
741
+ anchor: "middle" | "end" | "start";
742
+ }[];
743
+ legend: {
744
+ label: string;
745
+ color: string;
746
+ }[];
747
+ width: number;
748
+ height: number;
749
+ };
750
+
751
+ export { type AlignValue, type AsyncLabelCode, type AsyncLabelConfig, type AsyncLabelOptions, type AsyncLabelState, AsyncLabelStore, type AutocompleteProps, type BadgeProps, type BaseUIProps, type BorderProps, type BreadcrumbItem, type BreadcrumbProps, type BreakpointName, type ButtonGroupProps, type ButtonProps, type CSSLength, type CSSVariableStyle, type CardProps, type CarouselProps, type ChartData, type ChartProps, type ChartSeries, type ChartType, type ColorPalette, type ColorScale, type ColorShade, type ColorValue, type ComponentSize, type ComponentVariant, type DateTimeMode, type DateTimeProps, type DeepPartial, type DialogPosition, type DimensionValue, type DisableableProps, type DividerProps, type DropdownBehaviorProps, type DropdownModel, type FieldFocusStyle, type FileUploadProps, type FlexContainerProps, type FlexDirection, type FlexItemProps, type FlexWrap, type FlowAction, type FlowActionItemStyle, type FlowIconStyle, type FlowInputMode, type FlowStage, type FlowStageStyle, type FlowTextStyle, type FlowUIStyle, type FlowUITheme, type FocusableProps, type HStackProps, type IconProps, type ImageProps, type InputProps, type JustifyValue, type KnobProps, type LabelLookup, type LabelProps, type LabelResolverContext, type LabelResults, type LayoutProps, type ListboxProps, type LoadingProps, type MenuItem, type MultiSelectProps, type NotificationAction, type NotificationHorizontal, type NotificationProps, type NotificationType, type NotificationVertical, type OTPInputProps, type Orientation, type PaletteColor, type PasswordInputProps, type PhoneCountry, type PhoneInputProps, type PhoneNumberValue, type PopoverProps, type PositionProps, type PositionValue, type RadiusToken, type RadiusValue, type RatingProps, type ReadOnlyProps, type RequiredProps, type ResolvedStyle, type ResponsiveObject, type ResponsiveValue, type SchemeColor, type SelectOption, type SelectionValue, type SliderProps, type SortDirection, type SortState, type SpacingProps, type SpacingToken, type SpacingValue, type StackProps, type StyleResolution, type SwitchProps, type TabItem, type TabSelectedStyle, type TableColumn, type TableLoadMoreContext, type ThemeColorScheme, type ThemeMode, type TimelineItem, type TimelineProps, type TooltipLocation, type TooltipProps, type TreeDropdownProps, type TreeModel, type TreeMultiSelectProps, type TreeProps, type TypographyProps, type VStackProps, type VisualProps, type WorkflowStepperProps, buildChart, clampNumber, createAsyncLabelStore, createNotificationTimer, createTheme, defaultTheme, enabledSelectableDescendants, exportTableToCsv, exportTableToExcel, exportTableToPdf, filterTree, flattenTree, flowClass, formatLocalDateTime, notificationDuration, numericInputError, resolveColorValue, resolveFlowStyle, resolveTooltipLocation, responsiveCSS, sanitizeInputValue, selectedTreeModels, setLocalDayBoundary, tableToCsv, themeToCSS, toggleTreeCheck, treeCheckState };
package/dist/index.d.ts CHANGED
@@ -279,6 +279,7 @@ interface DropdownModel {
279
279
  group?: string | number;
280
280
  }
281
281
  interface TreeModel extends DropdownModel {
282
+ icon?: string;
282
283
  children?: TreeModel[];
283
284
  selectable?: boolean;
284
285
  hasChildren?: boolean;
@@ -369,6 +370,8 @@ interface PasswordInputProps extends Omit<InputProps, "type"> {
369
370
  visible?: boolean;
370
371
  }
371
372
  interface TreeProps extends BaseUIProps {
373
+ showCheckboxes?: boolean;
374
+ checkedValues?: readonly (string | number)[];
372
375
  nodes: TreeModel[];
373
376
  value?: string | number;
374
377
  defaultExpanded?: boolean;
@@ -506,8 +509,9 @@ interface PhoneInputProps extends BaseUIProps, DisableableProps {
506
509
  placeholder?: string;
507
510
  name?: string;
508
511
  }
509
- type ChartType = "bar" | "line" | "pie" | "doughnut";
512
+ type ChartType = "bar" | "column" | "horizontal-bar" | "line" | "area" | "combo" | "pie" | "doughnut";
510
513
  interface ChartSeries {
514
+ type?: "column" | "line";
511
515
  name: string;
512
516
  data: number[];
513
517
  color?: ColorValue;
@@ -548,6 +552,8 @@ declare function flattenTree(nodes: TreeModel[]): TreeModel[];
548
552
  declare function enabledSelectableDescendants(node: TreeModel): TreeModel[];
549
553
  declare function filterTree(nodes: TreeModel[], query: string): TreeModel[];
550
554
  declare function selectedTreeModels(nodes: TreeModel[], values: SelectionValue[]): TreeModel[];
555
+ declare function treeCheckState(node: TreeModel, selected: ReadonlySet<SelectionValue>): boolean | "mixed";
556
+ declare function toggleTreeCheck(node: TreeModel, values: readonly SelectionValue[]): SelectionValue[];
551
557
 
552
558
  /** Code-to-text results. null is a confirmed missing value; absent keys are errors. */
553
559
  type LabelResults = Readonly<Record<string, string | null>>;
@@ -652,4 +658,94 @@ interface NotificationAction {
652
658
  onClick: () => void | Promise<void>;
653
659
  }
654
660
 
655
- export { type AlignValue, type AsyncLabelCode, type AsyncLabelConfig, type AsyncLabelOptions, type AsyncLabelState, AsyncLabelStore, type AutocompleteProps, type BadgeProps, type BaseUIProps, type BorderProps, type BreadcrumbItem, type BreadcrumbProps, type BreakpointName, type ButtonGroupProps, type ButtonProps, type CSSLength, type CSSVariableStyle, type CardProps, type CarouselProps, type ChartData, type ChartProps, type ChartSeries, type ChartType, type ColorPalette, type ColorScale, type ColorShade, type ColorValue, type ComponentSize, type ComponentVariant, type DateTimeMode, type DateTimeProps, type DeepPartial, type DialogPosition, type DimensionValue, type DisableableProps, type DividerProps, type DropdownBehaviorProps, type DropdownModel, type FieldFocusStyle, type FileUploadProps, type FlexContainerProps, type FlexDirection, type FlexItemProps, type FlexWrap, type FlowInputMode, type FlowUIStyle, type FlowUITheme, type FocusableProps, type HStackProps, type IconProps, type ImageProps, type InputProps, type JustifyValue, type KnobProps, type LabelLookup, type LabelProps, type LabelResolverContext, type LabelResults, type LayoutProps, type ListboxProps, type LoadingProps, type MenuItem, type MultiSelectProps, type NotificationAction, type NotificationHorizontal, type NotificationProps, type NotificationType, type NotificationVertical, type OTPInputProps, type Orientation, type PaletteColor, type PasswordInputProps, type PhoneCountry, type PhoneInputProps, type PhoneNumberValue, type PopoverProps, type PositionProps, type PositionValue, type RadiusToken, type RadiusValue, type RatingProps, type ReadOnlyProps, type RequiredProps, type ResolvedStyle, type ResponsiveObject, type ResponsiveValue, type SchemeColor, type SelectOption, type SelectionValue, type SliderProps, type SortDirection, type SortState, type SpacingProps, type SpacingToken, type SpacingValue, type StackProps, type StyleResolution, type SwitchProps, type TabItem, type TabSelectedStyle, type TableColumn, type TableLoadMoreContext, type ThemeColorScheme, type ThemeMode, type TimelineItem, type TimelineProps, type TooltipLocation, type TooltipProps, type TreeDropdownProps, type TreeModel, type TreeMultiSelectProps, type TreeProps, type TypographyProps, type VStackProps, type VisualProps, clampNumber, createAsyncLabelStore, createNotificationTimer, createTheme, defaultTheme, enabledSelectableDescendants, exportTableToCsv, exportTableToExcel, exportTableToPdf, filterTree, flattenTree, flowClass, formatLocalDateTime, notificationDuration, numericInputError, resolveColorValue, resolveFlowStyle, resolveTooltipLocation, responsiveCSS, sanitizeInputValue, selectedTreeModels, setLocalDayBoundary, tableToCsv, themeToCSS };
661
+ interface FlowTextStyle {
662
+ color?: string;
663
+ fontFamily?: string;
664
+ fontSize?: number;
665
+ fontWeight?: "normal" | "bold" | "400" | "500" | "600" | "700";
666
+ lineHeight?: number;
667
+ textAlign?: "left" | "center" | "right";
668
+ }
669
+ interface FlowIconStyle {
670
+ color?: string;
671
+ size?: number;
672
+ }
673
+ interface FlowAction {
674
+ Label: string;
675
+ Icon?: string;
676
+ IsReadonly?: boolean;
677
+ TextStyle?: FlowTextStyle;
678
+ IconStyle?: FlowIconStyle;
679
+ }
680
+ interface FlowStage {
681
+ Id: string;
682
+ Label: string;
683
+ IsCurrent?: boolean;
684
+ IsCompleted?: boolean;
685
+ IsDisabled?: boolean;
686
+ Actions?: readonly FlowAction[];
687
+ SelectedAction?: FlowAction;
688
+ TextStyle?: FlowTextStyle;
689
+ }
690
+ interface FlowStageStyle {
691
+ backgroundColor?: string;
692
+ icon?: string;
693
+ iconStyle?: FlowIconStyle;
694
+ textStyle?: FlowTextStyle;
695
+ }
696
+ interface FlowActionItemStyle {
697
+ backgroundColor?: string;
698
+ textStyle?: FlowTextStyle;
699
+ iconStyle?: FlowIconStyle;
700
+ }
701
+ interface WorkflowStepperProps extends BaseUIProps {
702
+ stages: readonly FlowStage[];
703
+ direction?: "horizontal" | "vertical";
704
+ labelPosition?: "above" | "below" | "beside";
705
+ lineColor?: string;
706
+ stageTextStyle?: FlowTextStyle;
707
+ completedStyle?: FlowStageStyle;
708
+ currentStyle?: FlowStageStyle;
709
+ disabledStyle?: FlowStageStyle;
710
+ actionMenuStyle?: {
711
+ backgroundColor?: string;
712
+ borderColor?: string;
713
+ borderRadius?: number;
714
+ boxShadow?: string;
715
+ };
716
+ actionItemStyle?: FlowActionItemStyle & {
717
+ hover?: FlowActionItemStyle;
718
+ selected?: FlowActionItemStyle;
719
+ readonly?: FlowActionItemStyle;
720
+ };
721
+ checkmarkStyle?: FlowIconStyle;
722
+ chevronStyle?: FlowIconStyle;
723
+ }
724
+
725
+ type Mark = {
726
+ fill: string;
727
+ path?: string;
728
+ stroke?: string;
729
+ opacity?: number;
730
+ x?: number;
731
+ y?: number;
732
+ width?: number;
733
+ height?: number;
734
+ };
735
+ declare function buildChart(data: ChartData, type: ChartType, height: number, showValues: boolean): {
736
+ marks: Mark[];
737
+ labels: {
738
+ x: number;
739
+ y: number;
740
+ text: string;
741
+ anchor: "middle" | "end" | "start";
742
+ }[];
743
+ legend: {
744
+ label: string;
745
+ color: string;
746
+ }[];
747
+ width: number;
748
+ height: number;
749
+ };
750
+
751
+ export { type AlignValue, type AsyncLabelCode, type AsyncLabelConfig, type AsyncLabelOptions, type AsyncLabelState, AsyncLabelStore, type AutocompleteProps, type BadgeProps, type BaseUIProps, type BorderProps, type BreadcrumbItem, type BreadcrumbProps, type BreakpointName, type ButtonGroupProps, type ButtonProps, type CSSLength, type CSSVariableStyle, type CardProps, type CarouselProps, type ChartData, type ChartProps, type ChartSeries, type ChartType, type ColorPalette, type ColorScale, type ColorShade, type ColorValue, type ComponentSize, type ComponentVariant, type DateTimeMode, type DateTimeProps, type DeepPartial, type DialogPosition, type DimensionValue, type DisableableProps, type DividerProps, type DropdownBehaviorProps, type DropdownModel, type FieldFocusStyle, type FileUploadProps, type FlexContainerProps, type FlexDirection, type FlexItemProps, type FlexWrap, type FlowAction, type FlowActionItemStyle, type FlowIconStyle, type FlowInputMode, type FlowStage, type FlowStageStyle, type FlowTextStyle, type FlowUIStyle, type FlowUITheme, type FocusableProps, type HStackProps, type IconProps, type ImageProps, type InputProps, type JustifyValue, type KnobProps, type LabelLookup, type LabelProps, type LabelResolverContext, type LabelResults, type LayoutProps, type ListboxProps, type LoadingProps, type MenuItem, type MultiSelectProps, type NotificationAction, type NotificationHorizontal, type NotificationProps, type NotificationType, type NotificationVertical, type OTPInputProps, type Orientation, type PaletteColor, type PasswordInputProps, type PhoneCountry, type PhoneInputProps, type PhoneNumberValue, type PopoverProps, type PositionProps, type PositionValue, type RadiusToken, type RadiusValue, type RatingProps, type ReadOnlyProps, type RequiredProps, type ResolvedStyle, type ResponsiveObject, type ResponsiveValue, type SchemeColor, type SelectOption, type SelectionValue, type SliderProps, type SortDirection, type SortState, type SpacingProps, type SpacingToken, type SpacingValue, type StackProps, type StyleResolution, type SwitchProps, type TabItem, type TabSelectedStyle, type TableColumn, type TableLoadMoreContext, type ThemeColorScheme, type ThemeMode, type TimelineItem, type TimelineProps, type TooltipLocation, type TooltipProps, type TreeDropdownProps, type TreeModel, type TreeMultiSelectProps, type TreeProps, type TypographyProps, type VStackProps, type VisualProps, type WorkflowStepperProps, buildChart, clampNumber, createAsyncLabelStore, createNotificationTimer, createTheme, defaultTheme, enabledSelectableDescendants, exportTableToCsv, exportTableToExcel, exportTableToPdf, filterTree, flattenTree, flowClass, formatLocalDateTime, notificationDuration, numericInputError, resolveColorValue, resolveFlowStyle, resolveTooltipLocation, responsiveCSS, sanitizeInputValue, selectedTreeModels, setLocalDayBoundary, tableToCsv, themeToCSS, toggleTreeCheck, treeCheckState };
package/dist/index.js CHANGED
@@ -677,6 +677,22 @@ function selectedTreeModels(nodes, values) {
677
677
  const selected = new Set(values);
678
678
  return flattenTree(nodes).filter((node) => selected.has(node.value));
679
679
  }
680
+ function treeCheckState(node, selected) {
681
+ const leaves = enabledSelectableDescendants(node);
682
+ const checked = leaves.filter((leaf) => selected.has(leaf.value)).length;
683
+ if (!checked) return false;
684
+ return checked === leaves.length ? true : "mixed";
685
+ }
686
+ function toggleTreeCheck(node, values) {
687
+ const selected = new Set(values);
688
+ if (node.disabled || node.selectable === false) return [...selected];
689
+ const remove = treeCheckState(node, selected) === true;
690
+ for (const leaf of enabledSelectableDescendants(node)) {
691
+ if (remove) selected.delete(leaf.value);
692
+ else selected.add(leaf.value);
693
+ }
694
+ return [...selected];
695
+ }
680
696
 
681
697
  // src/async-label.ts
682
698
  var idle = Object.freeze({ status: "idle" });
@@ -1031,8 +1047,150 @@ function createNotificationTimer(duration, onElapsed) {
1031
1047
  }
1032
1048
  };
1033
1049
  }
1050
+
1051
+ // src/chart.ts
1052
+ var palette = ["#3b82c4", "#f59429", "#8cba39", "#ed74a7", "#8762c8"];
1053
+ function buildChart(data, type, height, showValues) {
1054
+ const width = 640;
1055
+ const marks = [];
1056
+ const labels = [];
1057
+ const label = (x2, y2, text, anchor = "middle") => labels.push({ x: x2, y: y2, text: String(text), anchor });
1058
+ const legend = data.series.map((series, index) => ({
1059
+ label: series.name,
1060
+ color: series.color ? resolveColorValue(series.color) : palette[index % palette.length]
1061
+ }));
1062
+ const colorAt = (index) => palette[index % palette.length];
1063
+ const path = (d, fill = "none", stroke, opacity) => marks.push({ path: d, fill, stroke, opacity });
1064
+ if (type === "pie" || type === "doughnut") {
1065
+ const values2 = (data.series[0]?.data ?? []).map(
1066
+ (value) => Math.max(0, value)
1067
+ );
1068
+ const total = values2.reduce((sum, value) => sum + value, 0);
1069
+ const radius = height * 0.38;
1070
+ const centerX = width / 2;
1071
+ const centerY = height / 2;
1072
+ const point = (r, angle) => [
1073
+ centerX + r * Math.cos(angle),
1074
+ centerY + r * Math.sin(angle)
1075
+ ];
1076
+ let start = -Math.PI / 2;
1077
+ values2.forEach((value, index) => {
1078
+ if (!value || !total) return;
1079
+ const sweep = 2 * Math.PI * value / total;
1080
+ const end = start + Math.min(sweep, 2 * Math.PI - 1e-4);
1081
+ const inner = type === "doughnut" ? radius * 0.55 : 0;
1082
+ const large = sweep > Math.PI ? 1 : 0;
1083
+ const tail = inner ? `L ${point(inner, end)} A ${inner},${inner} 0 ${large} 0 ${point(inner, start)}` : `L ${centerX},${centerY}`;
1084
+ path(
1085
+ `M ${point(radius, start)} A ${radius},${radius} 0 ${large} 1 ${point(radius, end)} ${tail} Z`,
1086
+ colorAt(index),
1087
+ "white"
1088
+ );
1089
+ if (showValues) {
1090
+ const [x2, y2] = point(radius * 0.75, (start + end) / 2);
1091
+ label(x2, y2, value);
1092
+ }
1093
+ start += sweep;
1094
+ });
1095
+ return {
1096
+ marks,
1097
+ labels,
1098
+ legend: values2.map((_, index) => ({
1099
+ label: data.labels[index] ?? String(index + 1),
1100
+ color: colorAt(index)
1101
+ })),
1102
+ width,
1103
+ height
1104
+ };
1105
+ }
1106
+ const left = type === "horizontal-bar" ? 120 : 48;
1107
+ const right = width - 28;
1108
+ const top = 24;
1109
+ const bottom = height - 34;
1110
+ const values = data.series.flatMap((series) => series.data);
1111
+ const min = Math.min(0, ...values);
1112
+ const max = Math.max(1, ...values);
1113
+ const groupCount = Math.max(
1114
+ 1,
1115
+ data.labels.length,
1116
+ ...data.series.map((series) => series.data.length)
1117
+ );
1118
+ const groupWidth = (right - left) / groupCount;
1119
+ const groupHeight = (bottom - top) / groupCount;
1120
+ const x = (index) => left + groupWidth * (index + 0.5);
1121
+ const y = (value) => bottom - (value - min) / (max - min) * (bottom - top);
1122
+ const scaleX = (value) => left + (value - min) / (max - min) * (right - left);
1123
+ const horizontal = type === "horizontal-bar";
1124
+ path(
1125
+ horizontal ? `M ${left} ${top} V ${bottom} H ${right} M ${scaleX(0)} ${top} V ${bottom}` : `M ${left} ${top} V ${y(0)} H ${right}`,
1126
+ "none",
1127
+ "#cbd5e1"
1128
+ );
1129
+ data.labels.forEach(
1130
+ (item, index) => horizontal ? label(left - 10, top + groupHeight * (index + 0.5) + 4, item, "end") : label(x(index), height - 10, item)
1131
+ );
1132
+ const isLine = (index) => type === "line" || type === "area" || type === "combo" && (data.series[index].type ?? (index === data.series.length - 1 ? "line" : "column")) === "line";
1133
+ const columns = data.series.filter((_, index) => !isLine(index));
1134
+ data.series.forEach((series, index) => {
1135
+ if (isLine(index)) return;
1136
+ const columnIndex = columns.indexOf(series);
1137
+ const size = (horizontal ? groupHeight : groupWidth) * 0.68 / columns.length;
1138
+ series.data.forEach((value, valueIndex) => {
1139
+ const fill = type === "bar" || series.color || columns.length > 1 ? legend[index].color : colorAt(valueIndex);
1140
+ if (horizontal) {
1141
+ const rowY = top + groupHeight * (valueIndex + 0.5) + (columnIndex - columns.length / 2) * size;
1142
+ marks.push({
1143
+ x: Math.min(scaleX(0), scaleX(value)),
1144
+ y: rowY,
1145
+ width: Math.abs(scaleX(value) - scaleX(0)),
1146
+ height: Math.max(1, size - 3),
1147
+ fill
1148
+ });
1149
+ if (showValues)
1150
+ label(
1151
+ scaleX(value) + (value < 0 ? -4 : 4),
1152
+ rowY + size / 2 + 4,
1153
+ value,
1154
+ value < 0 ? "end" : "start"
1155
+ );
1156
+ } else {
1157
+ const columnX = x(valueIndex) + (columnIndex - columns.length / 2) * size;
1158
+ marks.push({
1159
+ x: columnX,
1160
+ y: Math.min(y(0), y(value)),
1161
+ width: Math.max(1, size - 3),
1162
+ height: Math.abs(y(0) - y(value)),
1163
+ fill
1164
+ });
1165
+ if (showValues) label(columnX + size / 2, y(value) - 6, value);
1166
+ }
1167
+ });
1168
+ });
1169
+ data.series.forEach((series, index) => {
1170
+ if (!isLine(index) || !series.data.length) return;
1171
+ const coordinates = series.data.map(
1172
+ (value, valueIndex) => `${x(valueIndex)},${y(value)}`
1173
+ );
1174
+ const trace = `M ${coordinates.join(" L ")}`;
1175
+ if (type === "area") {
1176
+ path(
1177
+ `${trace} L ${x(coordinates.length - 1)},${y(0)} L ${x(0)},${y(0)} Z`,
1178
+ legend[index].color,
1179
+ void 0,
1180
+ 0.28
1181
+ );
1182
+ }
1183
+ path(trace, "none", legend[index].color);
1184
+ if (showValues)
1185
+ series.data.forEach(
1186
+ (value, valueIndex) => label(x(valueIndex), y(value) - 8, value)
1187
+ );
1188
+ });
1189
+ return { marks, labels, legend, width, height };
1190
+ }
1034
1191
  export {
1035
1192
  AsyncLabelStore,
1193
+ buildChart,
1036
1194
  clampNumber,
1037
1195
  createAsyncLabelStore,
1038
1196
  createNotificationTimer,
@@ -1056,5 +1214,7 @@ export {
1056
1214
  selectedTreeModels,
1057
1215
  setLocalDayBoundary,
1058
1216
  tableToCsv,
1059
- themeToCSS
1217
+ themeToCSS,
1218
+ toggleTreeCheck,
1219
+ treeCheckState
1060
1220
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akin2unde/flowui-core",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Framework-independent contracts, themes and style resolution for FlowUI.",
5
5
  "author": "Akintunde Morakinyo",
6
6
  "repository": {