juxscript 1.0.18 → 1.0.20

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.
Files changed (44) hide show
  1. package/lib/components/alert.ts +124 -128
  2. package/lib/components/areachart.ts +169 -287
  3. package/lib/components/areachartsmooth.ts +2 -2
  4. package/lib/components/badge.ts +63 -72
  5. package/lib/components/barchart.ts +120 -48
  6. package/lib/components/button.ts +99 -101
  7. package/lib/components/card.ts +97 -121
  8. package/lib/components/chart-types.ts +159 -0
  9. package/lib/components/chart-utils.ts +160 -0
  10. package/lib/components/chart.ts +628 -48
  11. package/lib/components/checkbox.ts +137 -51
  12. package/lib/components/code.ts +89 -75
  13. package/lib/components/container.ts +1 -1
  14. package/lib/components/datepicker.ts +93 -78
  15. package/lib/components/dialog.ts +163 -130
  16. package/lib/components/divider.ts +111 -193
  17. package/lib/components/docs-data.json +711 -264
  18. package/lib/components/doughnutchart.ts +125 -57
  19. package/lib/components/dropdown.ts +172 -85
  20. package/lib/components/element.ts +66 -61
  21. package/lib/components/fileupload.ts +142 -171
  22. package/lib/components/heading.ts +64 -21
  23. package/lib/components/hero.ts +109 -34
  24. package/lib/components/icon.ts +247 -0
  25. package/lib/components/icons.ts +174 -0
  26. package/lib/components/include.ts +77 -2
  27. package/lib/components/input.ts +174 -125
  28. package/lib/components/list.ts +120 -79
  29. package/lib/components/menu.ts +97 -2
  30. package/lib/components/modal.ts +144 -63
  31. package/lib/components/nav.ts +153 -52
  32. package/lib/components/paragraph.ts +78 -28
  33. package/lib/components/progress.ts +83 -107
  34. package/lib/components/radio.ts +151 -52
  35. package/lib/components/select.ts +110 -102
  36. package/lib/components/sidebar.ts +148 -105
  37. package/lib/components/switch.ts +124 -125
  38. package/lib/components/table.ts +214 -137
  39. package/lib/components/tabs.ts +194 -113
  40. package/lib/components/theme-toggle.ts +38 -7
  41. package/lib/components/tooltip.ts +207 -47
  42. package/lib/jux.ts +24 -5
  43. package/lib/reactivity/state.ts +13 -299
  44. package/package.json +1 -2
@@ -0,0 +1,159 @@
1
+ import { State } from '../reactivity/state.js';
2
+
3
+ /**
4
+ * Shared chart data point
5
+ */
6
+ export interface ChartDataPoint {
7
+ label: string;
8
+ value: number;
9
+ color?: string;
10
+ }
11
+
12
+ /**
13
+ * Shared chart theme type
14
+ */
15
+ export type ChartTheme = 'google' | 'seriesa' | 'hr' | 'figma' | 'notion' | 'chalk' | 'mint';
16
+
17
+ /**
18
+ * Shared chart style mode type
19
+ */
20
+ export type ChartStyleMode = 'default' | 'gradient' | 'outline' | 'dashed' | 'glow' | 'glass';
21
+
22
+ /**
23
+ * Shared chart orientation type
24
+ */
25
+ export type ChartOrientation = 'vertical' | 'horizontal';
26
+
27
+ /**
28
+ * Shared chart direction type
29
+ */
30
+ export type ChartDirection = 'normal' | 'reverse';
31
+
32
+ /**
33
+ * Shared legend orientation type
34
+ */
35
+ export type LegendOrientation = 'horizontal' | 'vertical';
36
+
37
+ /**
38
+ * Base chart options shared across all chart types
39
+ */
40
+ export interface BaseChartOptions {
41
+ data?: ChartDataPoint[];
42
+ title?: string;
43
+ subtitle?: string;
44
+ xAxisLabel?: string;
45
+ yAxisLabel?: string;
46
+ showTicksX?: boolean;
47
+ showTicksY?: boolean;
48
+ showScaleX?: boolean;
49
+ showScaleY?: boolean;
50
+ scaleXUnit?: string;
51
+ scaleYUnit?: string;
52
+ showLegend?: boolean;
53
+ legendOrientation?: LegendOrientation;
54
+ showDataTable?: boolean;
55
+ showDataLabels?: boolean;
56
+ animate?: boolean;
57
+ animationDuration?: number;
58
+ width?: number;
59
+ height?: number;
60
+ colors?: string[];
61
+ class?: string;
62
+ style?: string;
63
+ theme?: ChartTheme;
64
+ styleMode?: ChartStyleMode;
65
+ borderRadius?: number;
66
+ }
67
+
68
+ /**
69
+ * Bar/Area chart specific options (with orientation support)
70
+ */
71
+ export interface BarAreaChartOptions extends BaseChartOptions {
72
+ chartOrientation?: ChartOrientation;
73
+ chartDirection?: ChartDirection;
74
+ }
75
+
76
+ /**
77
+ * Doughnut chart specific options
78
+ */
79
+ export interface DoughnutChartOptions extends BaseChartOptions {
80
+ // Doughnut-specific options can be added here
81
+ }
82
+
83
+ /**
84
+ * Base chart state shared across all chart types
85
+ */
86
+ export interface BaseChartState {
87
+ data: ChartDataPoint[];
88
+ title: string;
89
+ subtitle: string;
90
+ xAxisLabel: string;
91
+ yAxisLabel: string;
92
+ showTicksX: boolean;
93
+ showTicksY: boolean;
94
+ showScaleX: boolean;
95
+ showScaleY: boolean;
96
+ scaleXUnit: string;
97
+ scaleYUnit: string;
98
+ showLegend: boolean;
99
+ legendOrientation: LegendOrientation;
100
+ showDataTable: boolean;
101
+ showDataLabels: boolean;
102
+ animate: boolean;
103
+ animationDuration: number;
104
+ width: number;
105
+ height: number;
106
+ colors: string[];
107
+ class: string;
108
+ style: string;
109
+ theme?: ChartTheme;
110
+ styleMode: ChartStyleMode;
111
+ borderRadius: number;
112
+ }
113
+
114
+ /**
115
+ * Bar/Area chart state with orientation
116
+ */
117
+ export interface BarAreaChartState extends BaseChartState {
118
+ chartOrientation: ChartOrientation;
119
+ chartDirection: ChartDirection;
120
+ }
121
+
122
+ /**
123
+ * Doughnut chart state
124
+ */
125
+ export interface DoughnutChartState extends BaseChartState {
126
+ // Doughnut-specific state can be added here
127
+ }
128
+
129
+ /**
130
+ * Property mapping for syncState
131
+ * Maps state property names to component method names
132
+ */
133
+ export interface ChartPropertyMapping {
134
+ [stateProperty: string]: string | ((value: any) => void);
135
+ }
136
+
137
+ /**
138
+ * Chart state object (all properties as State objects)
139
+ */
140
+ export interface ChartStateObject {
141
+ chartType?: State<string>;
142
+ chartTheme?: State<ChartTheme>;
143
+ chartStyleMode?: State<ChartStyleMode>;
144
+ borderRadius?: State<number>;
145
+ chartTitle?: State<string>;
146
+ chartWidth?: State<number>;
147
+ chartHeight?: State<number>;
148
+ showTicksX?: State<boolean>;
149
+ showTicksY?: State<boolean>;
150
+ showLegend?: State<boolean>;
151
+ showDataTable?: State<boolean>;
152
+ showDataLabels?: State<boolean>;
153
+ animate?: State<boolean>;
154
+ animationDuration?: State<number>;
155
+ legendOrientation?: State<LegendOrientation>;
156
+ chartOrientation?: State<ChartOrientation>;
157
+ chartDirection?: State<ChartDirection>;
158
+ [key: string]: State<any> | undefined;
159
+ }
@@ -0,0 +1,160 @@
1
+ import { ChartDataPoint, ChartTheme } from './chart-types.js';
2
+ import {
3
+ googleTheme,
4
+ seriesaTheme,
5
+ hrTheme,
6
+ figmaTheme,
7
+ notionTheme,
8
+ chalkTheme,
9
+ mintTheme
10
+ } from '../themes/charts.js';
11
+
12
+ /**
13
+ * Lighten a hex color by a percentage
14
+ */
15
+ export function lightenColor(color: string, percent: number): string {
16
+ const num = parseInt(color.replace('#', ''), 16);
17
+ const r = Math.min(255, Math.floor((num >> 16) + ((255 - (num >> 16)) * percent / 100)));
18
+ const g = Math.min(255, Math.floor(((num >> 8) & 0x00FF) + ((255 - ((num >> 8) & 0x00FF)) * percent / 100)));
19
+ const b = Math.min(255, Math.floor((num & 0x0000FF) + ((255 - (num & 0x0000FF)) * percent / 100)));
20
+ return `#${((r << 16) | (g << 8) | b).toString(16).padStart(6, '0')}`;
21
+ }
22
+
23
+ /**
24
+ * Get theme configuration by name
25
+ */
26
+ export function getThemeConfig(themeName: ChartTheme): any {
27
+ const themes: Record<ChartTheme, any> = {
28
+ google: googleTheme,
29
+ seriesa: seriesaTheme,
30
+ hr: hrTheme,
31
+ figma: figmaTheme,
32
+ notion: notionTheme,
33
+ chalk: chalkTheme,
34
+ mint: mintTheme
35
+ };
36
+ return themes[themeName];
37
+ }
38
+
39
+ /**
40
+ * Create legend HTML element
41
+ */
42
+ export function createLegend(data: ChartDataPoint[], colors: string[], className: string): HTMLElement {
43
+ const legend = document.createElement('div');
44
+ legend.className = `${className}-legend`;
45
+
46
+ data.forEach((point, index) => {
47
+ const color = point.color || colors[index % colors.length];
48
+
49
+ const item = document.createElement('div');
50
+ item.className = `${className}-legend-item`;
51
+
52
+ const swatch = document.createElement('div');
53
+ swatch.className = `${className}-legend-swatch`;
54
+ swatch.style.background = color;
55
+
56
+ const label = document.createElement('span');
57
+ label.className = `${className}-legend-label`;
58
+ label.textContent = point.label;
59
+
60
+ item.appendChild(swatch);
61
+ item.appendChild(label);
62
+ legend.appendChild(item);
63
+ });
64
+
65
+ return legend;
66
+ }
67
+
68
+ /**
69
+ * Create data table HTML element
70
+ */
71
+ export function createDataTable(
72
+ data: ChartDataPoint[],
73
+ xAxisLabel: string,
74
+ yAxisLabel: string,
75
+ className: string,
76
+ chartOrientation?: 'vertical' | 'horizontal'
77
+ ): HTMLElement {
78
+ const table = document.createElement('table');
79
+ table.className = `${className}-table`;
80
+
81
+ const thead = document.createElement('thead');
82
+ const headerRow = document.createElement('tr');
83
+
84
+ // Swap headers based on orientation for bar/area charts
85
+ const columnHeaders = chartOrientation === 'horizontal'
86
+ ? [yAxisLabel || 'Label', xAxisLabel || 'Value']
87
+ : [xAxisLabel || 'Label', yAxisLabel || 'Value'];
88
+
89
+ columnHeaders.forEach(text => {
90
+ const th = document.createElement('th');
91
+ th.textContent = text;
92
+ headerRow.appendChild(th);
93
+ });
94
+ thead.appendChild(headerRow);
95
+ table.appendChild(thead);
96
+
97
+ const tbody = document.createElement('tbody');
98
+ data.forEach(point => {
99
+ const row = document.createElement('tr');
100
+
101
+ const labelCell = document.createElement('td');
102
+ labelCell.textContent = point.label;
103
+
104
+ const valueCell = document.createElement('td');
105
+ valueCell.textContent = point.value.toString();
106
+
107
+ row.appendChild(labelCell);
108
+ row.appendChild(valueCell);
109
+ tbody.appendChild(row);
110
+ });
111
+ table.appendChild(tbody);
112
+
113
+ return table;
114
+ }
115
+
116
+ /**
117
+ * Apply theme styles to document
118
+ */
119
+ export function applyThemeStyles(themeName: ChartTheme, className: string, baseStyles: string): void {
120
+ const theme = getThemeConfig(themeName);
121
+ if (!theme) return;
122
+
123
+ // Inject base styles (once)
124
+ const baseStyleId = `${className}-base-styles`;
125
+ if (!document.getElementById(baseStyleId)) {
126
+ const style = document.createElement('style');
127
+ style.id = baseStyleId;
128
+ style.textContent = baseStyles;
129
+ document.head.appendChild(style);
130
+ }
131
+
132
+ // Inject font (once per theme)
133
+ if (theme.font && !document.querySelector(`link[href="${theme.font}"]`)) {
134
+ const link = document.createElement('link');
135
+ link.rel = 'stylesheet';
136
+ link.href = theme.font;
137
+ document.head.appendChild(link);
138
+ }
139
+
140
+ // Apply theme-specific styles
141
+ const styleId = `${className}-theme-${themeName}`;
142
+ let styleElement = document.getElementById(styleId) as HTMLStyleElement;
143
+
144
+ if (!styleElement) {
145
+ styleElement = document.createElement('style');
146
+ styleElement.id = styleId;
147
+ document.head.appendChild(styleElement);
148
+ }
149
+
150
+ // Generate CSS with theme variables
151
+ const variablesCSS = Object.entries(theme.variables)
152
+ .map(([key, value]) => ` ${key}: ${value};`)
153
+ .join('\n');
154
+
155
+ styleElement.textContent = `
156
+ .${className}.theme-${themeName} {
157
+ ${variablesCSS}
158
+ }
159
+ `;
160
+ }