juxscript 1.0.132 → 1.1.2

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 (133) hide show
  1. package/README.md +1 -32
  2. package/bin/cli.js +4 -2
  3. package/index.d.ts +200 -0
  4. package/index.js +96 -22
  5. package/juxconfig.example.js +58 -63
  6. package/lib/components/alert.ts +200 -0
  7. package/lib/components/app.ts +247 -0
  8. package/lib/components/badge.ts +101 -0
  9. package/lib/components/base/BaseComponent.ts +421 -0
  10. package/lib/components/base/FormInput.ts +227 -0
  11. package/lib/components/button.ts +178 -0
  12. package/lib/components/card.ts +173 -0
  13. package/lib/components/chart.ts +231 -0
  14. package/lib/components/checkbox.ts +242 -0
  15. package/lib/components/code.ts +123 -0
  16. package/lib/components/container.ts +140 -0
  17. package/lib/components/data.ts +135 -0
  18. package/lib/components/datepicker.ts +234 -0
  19. package/lib/components/dialog.ts +172 -0
  20. package/lib/components/divider.ts +100 -0
  21. package/lib/components/dropdown.ts +186 -0
  22. package/lib/components/element.ts +267 -0
  23. package/lib/components/fileupload.ts +309 -0
  24. package/lib/components/grid.ts +291 -0
  25. package/lib/components/guard.ts +92 -0
  26. package/lib/components/heading.ts +96 -0
  27. package/lib/components/helpers.ts +41 -0
  28. package/lib/components/hero.ts +224 -0
  29. package/lib/components/icon.ts +178 -0
  30. package/lib/components/icons.ts +464 -0
  31. package/lib/components/include.ts +410 -0
  32. package/lib/components/input.ts +457 -0
  33. package/lib/components/list.ts +419 -0
  34. package/lib/components/loading.ts +100 -0
  35. package/lib/components/menu.ts +275 -0
  36. package/lib/components/modal.ts +284 -0
  37. package/lib/components/nav.ts +257 -0
  38. package/lib/components/paragraph.ts +97 -0
  39. package/lib/components/progress.ts +159 -0
  40. package/lib/components/radio.ts +278 -0
  41. package/lib/components/req.ts +303 -0
  42. package/lib/components/script.ts +41 -0
  43. package/lib/components/select.ts +252 -0
  44. package/lib/components/sidebar.ts +275 -0
  45. package/lib/components/style.ts +41 -0
  46. package/lib/components/switch.ts +246 -0
  47. package/lib/components/table.ts +1249 -0
  48. package/lib/components/tabs.ts +250 -0
  49. package/lib/components/theme-toggle.ts +293 -0
  50. package/lib/components/tooltip.ts +144 -0
  51. package/lib/components/view.ts +190 -0
  52. package/lib/components/write.ts +272 -0
  53. package/lib/globals.d.ts +19 -5
  54. package/lib/layouts/default.css +260 -0
  55. package/lib/layouts/figma.css +334 -0
  56. package/lib/reactivity/state.ts +78 -0
  57. package/lib/utils/{fetch.js → fetch.ts} +206 -81
  58. package/machinery/ast.js +347 -0
  59. package/machinery/build.js +466 -0
  60. package/machinery/compiler3.js +6 -66
  61. package/machinery/config.js +6 -93
  62. package/machinery/doc-generator.js +136 -0
  63. package/machinery/imports.js +155 -0
  64. package/machinery/server.js +166 -0
  65. package/machinery/ts-shim.js +46 -0
  66. package/machinery/watcher.js +162 -50
  67. package/package.json +9 -30
  68. package/create/index.jux +0 -77
  69. package/create/layout.jux +0 -18
  70. package/create/style.css +0 -57
  71. package/create/themes/assets/jux.svg +0 -34
  72. package/create/themes/base.css +0 -197
  73. package/create/themes/base2.css +0 -54
  74. package/create/themes/layouts/base.jux +0 -16
  75. package/create/themes/layouts/base_marketing.jux +0 -0
  76. package/create/themes/layouts/base_saas.jux +0 -0
  77. package/lib/componentsv2/base/BaseEngine.d.ts +0 -112
  78. package/lib/componentsv2/base/BaseEngine.js +0 -279
  79. package/lib/componentsv2/base/BaseSkin.d.ts +0 -74
  80. package/lib/componentsv2/base/BaseSkin.js +0 -130
  81. package/lib/componentsv2/base/Neighborhood.d.ts +0 -22
  82. package/lib/componentsv2/base/Neighborhood.js +0 -56
  83. package/lib/componentsv2/base/OptionsContract.d.ts +0 -20
  84. package/lib/componentsv2/base/OptionsContract.js +0 -107
  85. package/lib/componentsv2/base/State.d.ts +0 -18
  86. package/lib/componentsv2/base/State.js +0 -68
  87. package/lib/componentsv2/element/Element.d.ts +0 -30
  88. package/lib/componentsv2/element/Element.js +0 -50
  89. package/lib/componentsv2/element/ElementEngine.d.ts +0 -59
  90. package/lib/componentsv2/element/ElementEngine.js +0 -118
  91. package/lib/componentsv2/element/ElementSkin.d.ts +0 -10
  92. package/lib/componentsv2/element/ElementSkin.js +0 -56
  93. package/lib/componentsv2/element/structure.css +0 -261
  94. package/lib/componentsv2/grid/Grid.d.ts +0 -13
  95. package/lib/componentsv2/grid/Grid.js +0 -27
  96. package/lib/componentsv2/grid/GridEngine.d.ts +0 -77
  97. package/lib/componentsv2/grid/GridEngine.js +0 -153
  98. package/lib/componentsv2/grid/GridSkin.d.ts +0 -11
  99. package/lib/componentsv2/grid/GridSkin.js +0 -84
  100. package/lib/componentsv2/grid/structure.css +0 -27
  101. package/lib/componentsv2/input/Input.d.ts +0 -6
  102. package/lib/componentsv2/input/Input.js +0 -21
  103. package/lib/componentsv2/input/InputEngine.d.ts +0 -70
  104. package/lib/componentsv2/input/InputEngine.js +0 -143
  105. package/lib/componentsv2/input/InputSkin.d.ts +0 -11
  106. package/lib/componentsv2/input/InputSkin.js +0 -89
  107. package/lib/componentsv2/input/structure.css +0 -47
  108. package/lib/componentsv2/list/List.d.ts +0 -49
  109. package/lib/componentsv2/list/List.js +0 -105
  110. package/lib/componentsv2/list/ListEngine.d.ts +0 -121
  111. package/lib/componentsv2/list/ListEngine.js +0 -322
  112. package/lib/componentsv2/list/ListSkin.d.ts +0 -20
  113. package/lib/componentsv2/list/ListSkin.js +0 -345
  114. package/lib/componentsv2/list/structure.css +0 -359
  115. package/lib/componentsv2/plugins/ClientSQLitePlugin.d.ts +0 -21
  116. package/lib/componentsv2/plugins/ClientSQLitePlugin.js +0 -130
  117. package/lib/componentsv2/plugins/IndexedDBPlugin.d.ts +0 -18
  118. package/lib/componentsv2/plugins/IndexedDBPlugin.js +0 -75
  119. package/lib/componentsv2/plugins/LocalStoragePlugin.d.ts +0 -20
  120. package/lib/componentsv2/plugins/LocalStoragePlugin.js +0 -65
  121. package/lib/componentsv2/plugins/ServerSQLitePlugin.d.ts +0 -25
  122. package/lib/componentsv2/plugins/ServerSQLitePlugin.js +0 -70
  123. package/lib/componentsv2/stubs/ComponentComposition.ts.stub +0 -32
  124. package/lib/componentsv2/stubs/ComponentEngine.ts.stub +0 -36
  125. package/lib/componentsv2/stubs/ComponentSkin.ts.stub +0 -35
  126. package/lib/componentsv2/stubs/ComponentStructure.css.d.ts.stub +0 -2
  127. package/lib/componentsv2/stubs/ComponentStructure.css.stub +0 -13
  128. package/lib/utils/fetch.d.ts +0 -176
  129. package/machinery/serve.js +0 -255
  130. package/types/css.d.ts +0 -10
  131. /package/{create/themes/layouts/base_blog.jux → machinery/bundleAssets.js} +0 -0
  132. /package/{create/themes/layouts/base_docs.jux → machinery/bundleJux.js} +0 -0
  133. /package/{create/themes/layouts/base_login.jux → machinery/bundleVendors.js} +0 -0
@@ -0,0 +1,250 @@
1
+ import { BaseComponent } from './base/BaseComponent.js';
2
+
3
+ // Event definitions
4
+ const TRIGGER_EVENTS = [] as const;
5
+ const CALLBACK_EVENTS = ['tabChange'] as const;
6
+
7
+ export interface Tab {
8
+ id: string;
9
+ label: string;
10
+ content: string | HTMLElement;
11
+ icon?: string;
12
+ }
13
+
14
+ export interface TabsOptions {
15
+ tabs?: Tab[];
16
+ activeTab?: string;
17
+ variant?: 'default' | 'pills' | 'underline';
18
+ style?: string;
19
+ class?: string;
20
+ }
21
+
22
+ type TabsState = {
23
+ tabs: Tab[];
24
+ activeTab: string;
25
+ variant: string;
26
+ style: string;
27
+ class: string;
28
+ };
29
+
30
+ export class Tabs extends BaseComponent<TabsState> {
31
+ constructor(id: string, options: TabsOptions = {}) {
32
+ super(id, {
33
+ tabs: options.tabs ?? [],
34
+ activeTab: options.activeTab ?? (options.tabs?.[0]?.id ?? ''),
35
+ variant: options.variant ?? 'default',
36
+ style: options.style ?? '',
37
+ class: options.class ?? ''
38
+ });
39
+ }
40
+
41
+ protected getTriggerEvents(): readonly string[] {
42
+ return TRIGGER_EVENTS;
43
+ }
44
+
45
+ protected getCallbackEvents(): readonly string[] {
46
+ return CALLBACK_EVENTS;
47
+ }
48
+
49
+ /* ═════════════════════════════════════════════════════════════════
50
+ * FLUENT API
51
+ * ═════════════════════════════════════════════════════════════════ */
52
+
53
+ // ✅ Inherited from BaseComponent
54
+
55
+ tabs(value: Tab[]): this {
56
+ this.state.tabs = value;
57
+ return this;
58
+ }
59
+
60
+ addTab(tab: Tab): this {
61
+ this.state.tabs = [...this.state.tabs, tab];
62
+ return this;
63
+ }
64
+
65
+ activeTab(value: string): this {
66
+ this.state.activeTab = value;
67
+ this._updateActiveTab();
68
+ return this;
69
+ }
70
+
71
+ variant(value: 'default' | 'pills' | 'underline'): this {
72
+ this.state.variant = value;
73
+ return this;
74
+ }
75
+
76
+ private _updateActiveTab(): void {
77
+ if (!this.container) return;
78
+ const wrapper = this.container.querySelector(`#${this._id}`);
79
+ if (!wrapper) return;
80
+
81
+ wrapper.querySelectorAll('.jux-tabs-button').forEach(btn => {
82
+ btn.classList.toggle('jux-tabs-button-active', btn.getAttribute('data-tab') === this.state.activeTab);
83
+ });
84
+
85
+ wrapper.querySelectorAll('.jux-tabs-panel').forEach(panel => {
86
+ const isActive = panel.getAttribute('data-tab') === this.state.activeTab;
87
+ panel.classList.toggle('jux-tabs-panel-active', isActive);
88
+ (panel as HTMLElement).style.display = isActive ? 'block' : 'none';
89
+ });
90
+ }
91
+
92
+ /* ═════════════════════════════════════════════════════════════════
93
+ * RENDER
94
+ * ═════════════════════════════════════════════════════════════════ */
95
+
96
+ render(targetId?: string): this {
97
+ const container = this._setupContainer(targetId);
98
+
99
+ const { tabs, activeTab, variant, style, class: className } = this.state;
100
+ const hasActiveTabSync = this._syncBindings.some(b => b.property === 'activeTab');
101
+
102
+ const wrapper = document.createElement('div');
103
+ wrapper.className = `jux-tabs jux-tabs-${variant}`;
104
+ wrapper.id = this._id;
105
+ if (className) wrapper.className += ` ${className}`;
106
+ if (style) wrapper.setAttribute('style', style);
107
+
108
+ const tabList = document.createElement('div');
109
+ tabList.className = 'jux-tabs-list';
110
+
111
+ const tabPanels = document.createElement('div');
112
+ tabPanels.className = 'jux-tabs-panels';
113
+
114
+ tabs.forEach(tab => {
115
+ const tabButton = document.createElement('button');
116
+ tabButton.className = 'jux-tabs-button';
117
+ tabButton.setAttribute('data-tab', tab.id);
118
+ if (tab.id === activeTab) tabButton.classList.add('jux-tabs-button-active');
119
+ tabButton.textContent = tab.label;
120
+ tabList.appendChild(tabButton);
121
+
122
+ const tabPanel = document.createElement('div');
123
+ tabPanel.className = 'jux-tabs-panel';
124
+ tabPanel.setAttribute('data-tab', tab.id);
125
+ if (tab.id === activeTab) {
126
+ tabPanel.classList.add('jux-tabs-panel-active');
127
+ } else {
128
+ tabPanel.style.display = 'none';
129
+ }
130
+ if (typeof tab.content === 'string') {
131
+ tabPanel.innerHTML = tab.content;
132
+ } else {
133
+ tabPanel.appendChild(tab.content);
134
+ }
135
+ tabPanels.appendChild(tabPanel);
136
+ });
137
+
138
+ wrapper.appendChild(tabList);
139
+ wrapper.appendChild(tabPanels);
140
+
141
+ if (!hasActiveTabSync) {
142
+ tabList.querySelectorAll('.jux-tabs-button').forEach(button => {
143
+ button.addEventListener('click', () => {
144
+ const tabId = button.getAttribute('data-tab')!;
145
+ this.state.activeTab = tabId;
146
+ this._switchTab(tabId, wrapper);
147
+ });
148
+ });
149
+ }
150
+
151
+ this._wireStandardEvents(wrapper);
152
+
153
+ this._syncBindings.forEach(({ property, stateObj, toState, toComponent }) => {
154
+ if (property === 'activeTab') {
155
+ const transformToState = toState || ((v: any) => String(v));
156
+ const transformToComponent = toComponent || ((v: any) => String(v));
157
+
158
+ let isUpdating = false;
159
+
160
+ stateObj.subscribe((val: any) => {
161
+ if (isUpdating) return;
162
+ const transformed = transformToComponent(val);
163
+ this.state.activeTab = transformed;
164
+ this._switchTab(transformed, wrapper);
165
+ });
166
+
167
+ tabList.querySelectorAll('.jux-tabs-button').forEach(button => {
168
+ button.addEventListener('click', () => {
169
+ if (isUpdating) return;
170
+ isUpdating = true;
171
+
172
+ const tabId = button.getAttribute('data-tab')!;
173
+ this.state.activeTab = tabId;
174
+ this._switchTab(tabId, wrapper);
175
+
176
+ const transformed = transformToState(tabId);
177
+ stateObj.set(transformed);
178
+
179
+ setTimeout(() => { isUpdating = false; }, 0);
180
+ });
181
+ });
182
+ }
183
+ else if (property === 'tabs') {
184
+ const transform = toComponent || ((v: any) => v);
185
+
186
+ stateObj.subscribe((val: any) => {
187
+ const transformed = transform(val);
188
+ this.state.tabs = transformed;
189
+
190
+ tabList.innerHTML = '';
191
+ tabPanels.innerHTML = '';
192
+
193
+ transformed.forEach((tab: any) => {
194
+ const tabButton = document.createElement('button');
195
+ tabButton.className = 'jux-tabs-button';
196
+ tabButton.setAttribute('data-tab', tab.id);
197
+ if (tab.id === this.state.activeTab) tabButton.classList.add('jux-tabs-button-active');
198
+ tabButton.textContent = tab.label;
199
+ tabList.appendChild(tabButton);
200
+
201
+ const tabPanel = document.createElement('div');
202
+ tabPanel.className = 'jux-tabs-panel';
203
+ tabPanel.setAttribute('data-tab', tab.id);
204
+ if (tab.id === this.state.activeTab) {
205
+ tabPanel.classList.add('jux-tabs-panel-active');
206
+ } else {
207
+ tabPanel.style.display = 'none';
208
+ }
209
+ if (typeof tab.content === 'string') {
210
+ tabPanel.innerHTML = tab.content;
211
+ } else {
212
+ tabPanel.appendChild(tab.content);
213
+ }
214
+ tabPanels.appendChild(tabPanel);
215
+ });
216
+
217
+ tabList.querySelectorAll('.jux-tabs-button').forEach(button => {
218
+ button.addEventListener('click', () => {
219
+ const tabId = button.getAttribute('data-tab')!;
220
+ this.state.activeTab = tabId;
221
+ this._switchTab(tabId, wrapper);
222
+ });
223
+ });
224
+ });
225
+ }
226
+ });
227
+
228
+ container.appendChild(wrapper);
229
+ return this;
230
+ }
231
+
232
+ private _switchTab(tabId: string, wrapper: HTMLElement): void {
233
+ wrapper.querySelectorAll('.jux-tabs-button').forEach(btn => {
234
+ btn.classList.toggle('jux-tabs-button-active', btn.getAttribute('data-tab') === tabId);
235
+ });
236
+
237
+ wrapper.querySelectorAll('.jux-tabs-panel').forEach(panel => {
238
+ const isActive = panel.getAttribute('data-tab') === tabId;
239
+ panel.classList.toggle('jux-tabs-panel-active', isActive);
240
+ (panel as HTMLElement).style.display = isActive ? 'block' : 'none';
241
+ });
242
+
243
+ // 🎯 Fire the tabChange callback event
244
+ this._triggerCallback('tabChange', tabId);
245
+ }
246
+ }
247
+
248
+ export function tabs(id: string, options: TabsOptions = {}): Tabs {
249
+ return new Tabs(id, options);
250
+ }
@@ -0,0 +1,293 @@
1
+ import { BaseComponent } from './base/BaseComponent.js';
2
+ import { renderIcon } from './icons.js';
3
+
4
+ // Event definitions
5
+ const TRIGGER_EVENTS = [] as const;
6
+ const CALLBACK_EVENTS = ['themeChange'] as const;
7
+
8
+ export interface Theme {
9
+ id: string;
10
+ label: string;
11
+ icon?: string;
12
+ iconCollection?: string;
13
+ }
14
+
15
+ export interface ThemeToggleOptions {
16
+ themes?: Theme[];
17
+ defaultTheme?: string;
18
+ storageKey?: string;
19
+ showLabel?: boolean;
20
+ variant?: 'button' | 'dropdown' | 'cycle';
21
+ style?: string;
22
+ class?: string;
23
+ }
24
+
25
+ type ThemeToggleState = {
26
+ themes: Theme[];
27
+ currentTheme: string;
28
+ storageKey: string;
29
+ showLabel: boolean;
30
+ variant: string;
31
+ style: string;
32
+ class: string;
33
+ };
34
+
35
+ export class ThemeToggle extends BaseComponent<ThemeToggleState> {
36
+ constructor(id: string, options: ThemeToggleOptions = {}) {
37
+ const defaultThemes: Theme[] = [
38
+ { id: 'light', label: 'Light', icon: '☀️' },
39
+ { id: 'dark', label: 'Dark', icon: '🌙' }
40
+ ];
41
+
42
+ super(id, {
43
+ themes: options.themes ?? defaultThemes,
44
+ currentTheme: options.defaultTheme ?? ThemeToggle.detectTheme(options.storageKey),
45
+ storageKey: options.storageKey ?? 'jux-theme',
46
+ showLabel: options.showLabel ?? false,
47
+ variant: options.variant ?? 'button',
48
+ style: options.style ?? '',
49
+ class: options.class ?? ''
50
+ });
51
+
52
+ // Apply theme on initialization
53
+ this.applyTheme(this.state.currentTheme);
54
+ }
55
+
56
+ protected getTriggerEvents(): readonly string[] {
57
+ return TRIGGER_EVENTS;
58
+ }
59
+
60
+ protected getCallbackEvents(): readonly string[] {
61
+ return CALLBACK_EVENTS;
62
+ }
63
+
64
+ /* ═════════════════════════════════════════════════════════════════
65
+ * STATIC METHODS
66
+ * ═════════════════════════════════════════════════════════════════ */
67
+
68
+ private static detectTheme(storageKey = 'jux-theme'): string {
69
+ if (typeof window === 'undefined') return 'light';
70
+
71
+ const stored = localStorage.getItem(storageKey);
72
+ if (stored) return stored;
73
+
74
+ const current = document.body.getAttribute('data-theme');
75
+ if (current) return current;
76
+
77
+ if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
78
+ return 'dark';
79
+ }
80
+
81
+ return 'light';
82
+ }
83
+
84
+ /* ═════════════════════════════════════════════════════════════════
85
+ * FLUENT API
86
+ * ═════════════════════════════════════════════════════════════════ */
87
+
88
+ // ✅ Inherited from BaseComponent
89
+
90
+ themes(value: Theme[]): this {
91
+ this.state.themes = value;
92
+ return this;
93
+ }
94
+
95
+ variant(value: 'button' | 'dropdown' | 'cycle'): this {
96
+ this.state.variant = value;
97
+ return this;
98
+ }
99
+
100
+ showLabel(value: boolean): this {
101
+ this.state.showLabel = value;
102
+ return this;
103
+ }
104
+
105
+ setTheme(themeId: string): this {
106
+ const theme = this.state.themes.find(t => t.id === themeId);
107
+
108
+ if (!theme) {
109
+ console.warn(`Theme "${themeId}" not found in available themes`);
110
+ return this;
111
+ }
112
+
113
+ this.state.currentTheme = themeId;
114
+ this.applyTheme(themeId);
115
+ this._updateDOM();
116
+
117
+ return this;
118
+ }
119
+
120
+ getTheme(): string {
121
+ return this.state.currentTheme;
122
+ }
123
+
124
+ addTheme(theme: Theme): this {
125
+ if (!this.state.themes.find(t => t.id === theme.id)) {
126
+ this.state.themes.push(theme);
127
+ }
128
+ return this;
129
+ }
130
+
131
+ /* ═════════════════════════════════════════════════════════════════
132
+ * PRIVATE METHODS
133
+ * ═════════════════════════════════════════════════════════════════ */
134
+
135
+ private applyTheme(themeId: string): void {
136
+ if (typeof document === 'undefined') return;
137
+
138
+ try {
139
+ document.body.setAttribute('data-theme', themeId);
140
+ document.documentElement.setAttribute('data-theme', themeId);
141
+ localStorage.setItem(this.state.storageKey, themeId);
142
+
143
+ window.dispatchEvent(new CustomEvent('themechange', {
144
+ detail: { theme: themeId }
145
+ }));
146
+
147
+ // 🎯 Fire the themeChange callback event
148
+ this._triggerCallback('themeChange', themeId);
149
+
150
+ console.log(`🎨 Theme applied: ${themeId}`);
151
+ } catch (error: any) {
152
+ throw new Error(`Failed to apply theme "${themeId}": ${error.message}`);
153
+ }
154
+ }
155
+
156
+ private cycleTheme(): void {
157
+ const currentIndex = this.state.themes.findIndex(t => t.id === this.state.currentTheme);
158
+ const nextIndex = (currentIndex + 1) % this.state.themes.length;
159
+ const nextTheme = this.state.themes[nextIndex];
160
+
161
+ this.setTheme(nextTheme.id);
162
+ }
163
+
164
+ private _updateDOM(): void {
165
+ if (!this.container) return;
166
+
167
+ const toggle = this.container.querySelector(`#${this._id}`);
168
+ if (!toggle) return;
169
+
170
+ const currentTheme = this.state.themes.find(t => t.id === this.state.currentTheme);
171
+ if (!currentTheme) return;
172
+
173
+ if (this.state.variant === 'button' || this.state.variant === 'cycle') {
174
+ const button = toggle.querySelector('button');
175
+ if (button && currentTheme.icon) {
176
+ button.innerHTML = '';
177
+ const iconElement = renderIcon(currentTheme.icon, currentTheme.iconCollection);
178
+ button.appendChild(iconElement);
179
+
180
+ if (this.state.showLabel) {
181
+ const labelSpan = document.createElement('span');
182
+ labelSpan.textContent = ` ${currentTheme.label}`;
183
+ button.appendChild(labelSpan);
184
+ }
185
+
186
+ requestAnimationFrame(() => {
187
+ if ((window as any).Iconify) {
188
+ (window as any).Iconify.scan();
189
+ }
190
+ });
191
+ }
192
+ }
193
+
194
+ if (this.state.variant === 'dropdown') {
195
+ const select = toggle.querySelector('select') as HTMLSelectElement;
196
+ if (select) {
197
+ select.value = this.state.currentTheme;
198
+ }
199
+ }
200
+ }
201
+
202
+ /* ═════════════════════════════════════════════════════════════════
203
+ * RENDER
204
+ * ═════════════════════════════════════════════════════════════════ */
205
+
206
+ render(targetId?: string): this {
207
+ const container = this._setupContainer(targetId);
208
+
209
+ const { themes, currentTheme, showLabel, variant, style, class: className } = this.state;
210
+
211
+ const wrapper = document.createElement('div');
212
+ wrapper.className = `jux-theme-toggle`;
213
+ wrapper.id = this._id;
214
+
215
+ if (className) {
216
+ wrapper.className += ` ${className}`;
217
+ }
218
+
219
+ if (style) {
220
+ wrapper.setAttribute('style', style);
221
+ }
222
+
223
+ const theme = themes.find(t => t.id === currentTheme);
224
+
225
+ if (variant === 'button' || variant === 'cycle') {
226
+ const button = document.createElement('button');
227
+ button.className = 'jux-theme-toggle-button';
228
+ button.type = 'button';
229
+ button.setAttribute('aria-label', 'Toggle theme');
230
+
231
+ if (theme?.icon) {
232
+ const iconElement = renderIcon(theme.icon, theme.iconCollection);
233
+ button.appendChild(iconElement);
234
+ }
235
+
236
+ if (showLabel) {
237
+ const labelSpan = document.createElement('span');
238
+ labelSpan.textContent = ` ${theme?.label || currentTheme}`;
239
+ button.appendChild(labelSpan);
240
+ } else if (!theme?.icon) {
241
+ button.textContent = theme?.label || currentTheme;
242
+ }
243
+
244
+ button.addEventListener('click', () => {
245
+ this.cycleTheme();
246
+ });
247
+
248
+ wrapper.appendChild(button);
249
+
250
+ } else if (variant === 'dropdown') {
251
+ const select = document.createElement('select');
252
+ select.className = 'jux-theme-toggle-select';
253
+ select.setAttribute('aria-label', 'Select theme');
254
+
255
+ themes.forEach(t => {
256
+ const option = document.createElement('option');
257
+ option.value = t.id;
258
+ option.textContent = showLabel
259
+ ? `${t.icon || ''} ${t.label}`.trim()
260
+ : t.icon || t.label;
261
+
262
+ if (t.id === currentTheme) {
263
+ option.selected = true;
264
+ }
265
+
266
+ select.appendChild(option);
267
+ });
268
+
269
+ select.addEventListener('change', (e) => {
270
+ const target = e.target as HTMLSelectElement;
271
+ this.setTheme(target.value);
272
+ });
273
+
274
+ wrapper.appendChild(select);
275
+ }
276
+
277
+ this._wireStandardEvents(wrapper);
278
+
279
+ container.appendChild(wrapper);
280
+
281
+ requestAnimationFrame(() => {
282
+ if ((window as any).Iconify) {
283
+ (window as any).Iconify.scan();
284
+ }
285
+ });
286
+
287
+ return this;
288
+ }
289
+ }
290
+
291
+ export function themeToggle(id: string, options: ThemeToggleOptions = {}): ThemeToggle {
292
+ return new ThemeToggle(id, options);
293
+ }
@@ -0,0 +1,144 @@
1
+ import { BaseComponent } from './base/BaseComponent.js';
2
+
3
+ // Event definitions
4
+ const TRIGGER_EVENTS = [] as const;
5
+ const CALLBACK_EVENTS = [] as const;
6
+
7
+ export interface TooltipOptions {
8
+ text?: string;
9
+ position?: 'top' | 'bottom' | 'left' | 'right';
10
+ style?: string;
11
+ class?: string;
12
+ }
13
+
14
+ type TooltipState = {
15
+ text: string;
16
+ position: string;
17
+ style: string;
18
+ class: string;
19
+ };
20
+
21
+ export class Tooltip extends BaseComponent<TooltipState> {
22
+ private _tooltip: HTMLElement | null = null;
23
+ private _target: HTMLElement | null = null;
24
+
25
+ constructor(id: string, options: TooltipOptions = {}) {
26
+ super(id, {
27
+ text: options.text ?? '',
28
+ position: options.position ?? 'top',
29
+ style: options.style ?? '',
30
+ class: options.class ?? ''
31
+ });
32
+ }
33
+
34
+ protected getTriggerEvents(): readonly string[] {
35
+ return TRIGGER_EVENTS;
36
+ }
37
+
38
+ protected getCallbackEvents(): readonly string[] {
39
+ return CALLBACK_EVENTS;
40
+ }
41
+
42
+ /* ═════════════════════════════════════════════════════════════════
43
+ * FLUENT API
44
+ * ═════════════════════════════════════════════════════════════════ */
45
+
46
+ text(value: string): this {
47
+ this.state.text = value;
48
+ return this;
49
+ }
50
+
51
+ position(value: 'top' | 'bottom' | 'left' | 'right'): this {
52
+ this.state.position = value;
53
+ return this;
54
+ }
55
+
56
+ attachTo(target: HTMLElement | null): this {
57
+ if (!target) return this;
58
+
59
+ this._target = target;
60
+ this._setupTooltip();
61
+ return this;
62
+ }
63
+
64
+ /* ═════════════════════════════════════════════════════════════════
65
+ * RENDER
66
+ * ═════════════════════════════════════════════════════════════════ */
67
+
68
+ private _setupTooltip(): void {
69
+ if (!this._target) return;
70
+
71
+ const { text, position, style, class: className } = this.state;
72
+
73
+ // Create tooltip element
74
+ const tooltip = document.createElement('div');
75
+ tooltip.className = `jux-tooltip jux-tooltip-${position}`;
76
+ tooltip.id = this._id;
77
+ if (className) tooltip.className += ` ${className}`;
78
+ if (style) tooltip.setAttribute('style', style);
79
+ tooltip.textContent = text;
80
+ tooltip.style.display = 'none';
81
+ this._tooltip = tooltip;
82
+
83
+ document.body.appendChild(tooltip);
84
+
85
+ // Show on hover
86
+ this._target.addEventListener('mouseenter', () => {
87
+ this._show();
88
+ });
89
+
90
+ this._target.addEventListener('mouseleave', () => {
91
+ this._hide();
92
+ });
93
+
94
+ }
95
+
96
+ private _show(): void {
97
+ if (!this._tooltip || !this._target) return;
98
+
99
+ const targetRect = this._target.getBoundingClientRect();
100
+ const tooltipRect = this._tooltip.getBoundingClientRect();
101
+
102
+ let top = 0;
103
+ let left = 0;
104
+
105
+ switch (this.state.position) {
106
+ case 'top':
107
+ top = targetRect.top - tooltipRect.height - 8;
108
+ left = targetRect.left + (targetRect.width - tooltipRect.width) / 2;
109
+ break;
110
+ case 'bottom':
111
+ top = targetRect.bottom + 8;
112
+ left = targetRect.left + (targetRect.width - tooltipRect.width) / 2;
113
+ break;
114
+ case 'left':
115
+ top = targetRect.top + (targetRect.height - tooltipRect.height) / 2;
116
+ left = targetRect.left - tooltipRect.width - 8;
117
+ break;
118
+ case 'right':
119
+ top = targetRect.top + (targetRect.height - tooltipRect.height) / 2;
120
+ left = targetRect.right + 8;
121
+ break;
122
+ }
123
+
124
+ this._tooltip.style.top = `${top}px`;
125
+ this._tooltip.style.left = `${left}px`;
126
+ this._tooltip.style.display = 'block';
127
+ }
128
+
129
+ private _hide(): void {
130
+ if (this._tooltip) {
131
+ this._tooltip.style.display = 'none';
132
+ }
133
+ }
134
+
135
+ render(targetId?: string): this {
136
+ // Tooltips don't render to containers, they attach to targets
137
+ console.warn('Tooltip: Use .attachTo(element) instead of .render()');
138
+ return this;
139
+ }
140
+ }
141
+
142
+ export function tooltip(id: string, options: TooltipOptions = {}): Tooltip {
143
+ return new Tooltip(id, options);
144
+ }