juxscript 1.1.4 → 1.1.6

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 (205) hide show
  1. package/index.d.ts +10 -10
  2. package/index.d.ts.map +1 -0
  3. package/lib/components/alert.d.ts +32 -0
  4. package/lib/components/alert.d.ts.map +1 -0
  5. package/lib/components/alert.js +153 -0
  6. package/lib/components/alert.ts +200 -0
  7. package/lib/components/app.d.ts +89 -0
  8. package/lib/components/app.d.ts.map +1 -0
  9. package/lib/components/app.js +175 -0
  10. package/lib/components/app.ts +247 -0
  11. package/lib/components/badge.d.ts +27 -0
  12. package/lib/components/badge.d.ts.map +1 -0
  13. package/lib/components/badge.js +70 -0
  14. package/lib/components/badge.ts +101 -0
  15. package/lib/components/base/BaseComponent.d.ts +142 -0
  16. package/lib/components/base/BaseComponent.d.ts.map +1 -0
  17. package/lib/components/base/BaseComponent.js +363 -0
  18. package/lib/components/base/BaseComponent.ts +421 -0
  19. package/lib/components/base/FormInput.d.ts +73 -0
  20. package/lib/components/base/FormInput.d.ts.map +1 -0
  21. package/lib/components/base/FormInput.js +163 -0
  22. package/lib/components/base/FormInput.ts +227 -0
  23. package/lib/components/button.d.ts +48 -0
  24. package/lib/components/button.d.ts.map +1 -0
  25. package/lib/components/button.js +121 -0
  26. package/lib/components/button.ts +178 -0
  27. package/lib/components/card.d.ts +34 -0
  28. package/lib/components/card.d.ts.map +1 -0
  29. package/lib/components/card.js +127 -0
  30. package/lib/components/card.ts +173 -0
  31. package/lib/components/chart.d.ts +45 -0
  32. package/lib/components/chart.d.ts.map +1 -0
  33. package/lib/components/chart.js +186 -0
  34. package/lib/components/chart.ts +231 -0
  35. package/lib/components/checkbox.d.ts +31 -0
  36. package/lib/components/checkbox.d.ts.map +1 -0
  37. package/lib/components/checkbox.js +185 -0
  38. package/lib/components/checkbox.ts +242 -0
  39. package/lib/components/code.d.ts +24 -0
  40. package/lib/components/code.d.ts.map +1 -0
  41. package/lib/components/code.js +88 -0
  42. package/lib/components/code.ts +123 -0
  43. package/lib/components/container.d.ts +42 -0
  44. package/lib/components/container.d.ts.map +1 -0
  45. package/lib/components/container.js +93 -0
  46. package/lib/components/container.ts +140 -0
  47. package/lib/components/data.d.ts +36 -0
  48. package/lib/components/data.d.ts.map +1 -0
  49. package/lib/components/data.js +110 -0
  50. package/lib/components/data.ts +135 -0
  51. package/lib/components/datepicker.d.ts +38 -0
  52. package/lib/components/datepicker.d.ts.map +1 -0
  53. package/lib/components/datepicker.js +177 -0
  54. package/lib/components/datepicker.ts +234 -0
  55. package/lib/components/dialog.d.ts +38 -0
  56. package/lib/components/dialog.d.ts.map +1 -0
  57. package/lib/components/dialog.js +126 -0
  58. package/lib/components/dialog.ts +172 -0
  59. package/lib/components/divider.d.ts +30 -0
  60. package/lib/components/divider.d.ts.map +1 -0
  61. package/lib/components/divider.js +69 -0
  62. package/lib/components/divider.ts +100 -0
  63. package/lib/components/dropdown.d.ts +39 -0
  64. package/lib/components/dropdown.d.ts.map +1 -0
  65. package/lib/components/dropdown.js +133 -0
  66. package/lib/components/dropdown.ts +186 -0
  67. package/lib/components/element.d.ts +50 -0
  68. package/lib/components/element.d.ts.map +1 -0
  69. package/lib/components/element.js +206 -0
  70. package/lib/components/element.ts +267 -0
  71. package/lib/components/fileupload.d.ts +40 -0
  72. package/lib/components/fileupload.d.ts.map +1 -0
  73. package/lib/components/fileupload.js +241 -0
  74. package/lib/components/fileupload.ts +309 -0
  75. package/lib/components/grid.d.ts +87 -0
  76. package/lib/components/grid.d.ts.map +1 -0
  77. package/lib/components/grid.js +205 -0
  78. package/lib/components/grid.ts +291 -0
  79. package/lib/components/guard.d.ts +41 -0
  80. package/lib/components/guard.d.ts.map +1 -0
  81. package/lib/components/guard.js +56 -0
  82. package/lib/components/guard.ts +92 -0
  83. package/lib/components/heading.d.ts +24 -0
  84. package/lib/components/heading.d.ts.map +1 -0
  85. package/lib/components/heading.js +67 -0
  86. package/lib/components/heading.ts +96 -0
  87. package/lib/components/helpers.d.ts +9 -0
  88. package/lib/components/helpers.d.ts.map +1 -0
  89. package/lib/components/helpers.js +30 -0
  90. package/lib/components/helpers.ts +41 -0
  91. package/lib/components/hero.d.ts +45 -0
  92. package/lib/components/hero.d.ts.map +1 -0
  93. package/lib/components/hero.js +165 -0
  94. package/lib/components/hero.ts +224 -0
  95. package/lib/components/icon.d.ts +35 -0
  96. package/lib/components/icon.d.ts.map +1 -0
  97. package/lib/components/icon.js +132 -0
  98. package/lib/components/icon.ts +178 -0
  99. package/lib/components/icons.d.ts +25 -0
  100. package/lib/components/icons.d.ts.map +1 -0
  101. package/lib/components/icons.js +440 -0
  102. package/lib/components/icons.ts +464 -0
  103. package/lib/components/include.d.ts +120 -0
  104. package/lib/components/include.d.ts.map +1 -0
  105. package/lib/components/include.js +350 -0
  106. package/lib/components/include.ts +410 -0
  107. package/lib/components/input.d.ts +83 -0
  108. package/lib/components/input.d.ts.map +1 -0
  109. package/lib/components/input.js +348 -0
  110. package/lib/components/input.ts +457 -0
  111. package/lib/components/list.d.ts +82 -0
  112. package/lib/components/list.d.ts.map +1 -0
  113. package/lib/components/list.js +311 -0
  114. package/lib/components/list.ts +419 -0
  115. package/lib/components/loading.d.ts +24 -0
  116. package/lib/components/loading.d.ts.map +1 -0
  117. package/lib/components/loading.js +73 -0
  118. package/lib/components/loading.ts +100 -0
  119. package/lib/components/menu.d.ts +37 -0
  120. package/lib/components/menu.d.ts.map +1 -0
  121. package/lib/components/menu.js +202 -0
  122. package/lib/components/menu.ts +275 -0
  123. package/lib/components/modal.d.ts +51 -0
  124. package/lib/components/modal.d.ts.map +1 -0
  125. package/lib/components/modal.js +227 -0
  126. package/lib/components/modal.ts +284 -0
  127. package/lib/components/nav.d.ts +45 -0
  128. package/lib/components/nav.d.ts.map +1 -0
  129. package/lib/components/nav.js +190 -0
  130. package/lib/components/nav.ts +257 -0
  131. package/lib/components/paragraph.d.ts +21 -0
  132. package/lib/components/paragraph.d.ts.map +1 -0
  133. package/lib/components/paragraph.js +70 -0
  134. package/lib/components/paragraph.ts +97 -0
  135. package/lib/components/progress.d.ts +39 -0
  136. package/lib/components/progress.d.ts.map +1 -0
  137. package/lib/components/progress.js +113 -0
  138. package/lib/components/progress.ts +159 -0
  139. package/lib/components/radio.d.ts +41 -0
  140. package/lib/components/radio.d.ts.map +1 -0
  141. package/lib/components/radio.js +203 -0
  142. package/lib/components/radio.ts +278 -0
  143. package/lib/components/req.d.ts +155 -0
  144. package/lib/components/req.d.ts.map +1 -0
  145. package/lib/components/req.js +253 -0
  146. package/lib/components/req.ts +303 -0
  147. package/lib/components/script.d.ts +14 -0
  148. package/lib/components/script.d.ts.map +1 -0
  149. package/lib/components/script.js +33 -0
  150. package/lib/components/script.ts +41 -0
  151. package/lib/components/select.d.ts +40 -0
  152. package/lib/components/select.d.ts.map +1 -0
  153. package/lib/components/select.js +183 -0
  154. package/lib/components/select.ts +252 -0
  155. package/lib/components/sidebar.d.ts +48 -0
  156. package/lib/components/sidebar.d.ts.map +1 -0
  157. package/lib/components/sidebar.js +207 -0
  158. package/lib/components/sidebar.ts +275 -0
  159. package/lib/components/style.d.ts +14 -0
  160. package/lib/components/style.d.ts.map +1 -0
  161. package/lib/components/style.js +33 -0
  162. package/lib/components/style.ts +41 -0
  163. package/lib/components/switch.d.ts +32 -0
  164. package/lib/components/switch.d.ts.map +1 -0
  165. package/lib/components/switch.js +186 -0
  166. package/lib/components/switch.ts +246 -0
  167. package/lib/components/table.d.ts +137 -0
  168. package/lib/components/table.d.ts.map +1 -0
  169. package/lib/components/table.js +1045 -0
  170. package/lib/components/table.ts +1249 -0
  171. package/lib/components/tabs.d.ts +36 -0
  172. package/lib/components/tabs.d.ts.map +1 -0
  173. package/lib/components/tabs.js +198 -0
  174. package/lib/components/tabs.ts +250 -0
  175. package/lib/components/theme-toggle.d.ts +44 -0
  176. package/lib/components/theme-toggle.d.ts.map +1 -0
  177. package/lib/components/theme-toggle.js +215 -0
  178. package/lib/components/theme-toggle.ts +293 -0
  179. package/lib/components/tooltip.d.ts +30 -0
  180. package/lib/components/tooltip.d.ts.map +1 -0
  181. package/lib/components/tooltip.js +109 -0
  182. package/lib/components/tooltip.ts +144 -0
  183. package/lib/components/view.d.ts +48 -0
  184. package/lib/components/view.d.ts.map +1 -0
  185. package/lib/components/view.js +149 -0
  186. package/lib/components/view.ts +190 -0
  187. package/lib/components/write.d.ts +107 -0
  188. package/lib/components/write.d.ts.map +1 -0
  189. package/lib/components/write.js +222 -0
  190. package/lib/components/write.ts +272 -0
  191. package/lib/layouts/default.css +260 -0
  192. package/lib/layouts/figma.css +334 -0
  193. package/lib/reactivity/state.d.ts +36 -0
  194. package/lib/reactivity/state.d.ts.map +1 -0
  195. package/lib/reactivity/state.js +67 -0
  196. package/lib/reactivity/state.ts +78 -0
  197. package/lib/utils/fetch.d.ts +176 -0
  198. package/lib/utils/fetch.d.ts.map +1 -0
  199. package/lib/utils/fetch.js +427 -0
  200. package/lib/utils/fetch.ts +553 -0
  201. package/machinery/compiler3.js +78 -0
  202. package/machinery/doc-generator.js +136 -0
  203. package/machinery/imports.js +155 -0
  204. package/machinery/ts-shim.js +46 -0
  205. package/package.json +9 -15
@@ -0,0 +1,215 @@
1
+ import { BaseComponent } from './base/BaseComponent.js';
2
+ import { renderIcon } from './icons.js';
3
+ // Event definitions
4
+ const TRIGGER_EVENTS = [];
5
+ const CALLBACK_EVENTS = ['themeChange'];
6
+ export class ThemeToggle extends BaseComponent {
7
+ constructor(id, options = {}) {
8
+ const defaultThemes = [
9
+ { id: 'light', label: 'Light', icon: '☀️' },
10
+ { id: 'dark', label: 'Dark', icon: '🌙' }
11
+ ];
12
+ super(id, {
13
+ themes: options.themes ?? defaultThemes,
14
+ currentTheme: options.defaultTheme ?? ThemeToggle.detectTheme(options.storageKey),
15
+ storageKey: options.storageKey ?? 'jux-theme',
16
+ showLabel: options.showLabel ?? false,
17
+ variant: options.variant ?? 'button',
18
+ style: options.style ?? '',
19
+ class: options.class ?? ''
20
+ });
21
+ // Apply theme on initialization
22
+ this.applyTheme(this.state.currentTheme);
23
+ }
24
+ getTriggerEvents() {
25
+ return TRIGGER_EVENTS;
26
+ }
27
+ getCallbackEvents() {
28
+ return CALLBACK_EVENTS;
29
+ }
30
+ /* ═════════════════════════════════════════════════════════════════
31
+ * STATIC METHODS
32
+ * ═════════════════════════════════════════════════════════════════ */
33
+ static detectTheme(storageKey = 'jux-theme') {
34
+ if (typeof window === 'undefined')
35
+ return 'light';
36
+ const stored = localStorage.getItem(storageKey);
37
+ if (stored)
38
+ return stored;
39
+ const current = document.body.getAttribute('data-theme');
40
+ if (current)
41
+ return current;
42
+ if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
43
+ return 'dark';
44
+ }
45
+ return 'light';
46
+ }
47
+ /* ═════════════════════════════════════════════════════════════════
48
+ * FLUENT API
49
+ * ═════════════════════════════════════════════════════════════════ */
50
+ // ✅ Inherited from BaseComponent
51
+ themes(value) {
52
+ this.state.themes = value;
53
+ return this;
54
+ }
55
+ variant(value) {
56
+ this.state.variant = value;
57
+ return this;
58
+ }
59
+ showLabel(value) {
60
+ this.state.showLabel = value;
61
+ return this;
62
+ }
63
+ setTheme(themeId) {
64
+ const theme = this.state.themes.find(t => t.id === themeId);
65
+ if (!theme) {
66
+ console.warn(`Theme "${themeId}" not found in available themes`);
67
+ return this;
68
+ }
69
+ this.state.currentTheme = themeId;
70
+ this.applyTheme(themeId);
71
+ this._updateDOM();
72
+ return this;
73
+ }
74
+ getTheme() {
75
+ return this.state.currentTheme;
76
+ }
77
+ addTheme(theme) {
78
+ if (!this.state.themes.find(t => t.id === theme.id)) {
79
+ this.state.themes.push(theme);
80
+ }
81
+ return this;
82
+ }
83
+ /* ═════════════════════════════════════════════════════════════════
84
+ * PRIVATE METHODS
85
+ * ═════════════════════════════════════════════════════════════════ */
86
+ applyTheme(themeId) {
87
+ if (typeof document === 'undefined')
88
+ return;
89
+ try {
90
+ document.body.setAttribute('data-theme', themeId);
91
+ document.documentElement.setAttribute('data-theme', themeId);
92
+ localStorage.setItem(this.state.storageKey, themeId);
93
+ window.dispatchEvent(new CustomEvent('themechange', {
94
+ detail: { theme: themeId }
95
+ }));
96
+ // 🎯 Fire the themeChange callback event
97
+ this._triggerCallback('themeChange', themeId);
98
+ console.log(`🎨 Theme applied: ${themeId}`);
99
+ }
100
+ catch (error) {
101
+ throw new Error(`Failed to apply theme "${themeId}": ${error.message}`);
102
+ }
103
+ }
104
+ cycleTheme() {
105
+ const currentIndex = this.state.themes.findIndex(t => t.id === this.state.currentTheme);
106
+ const nextIndex = (currentIndex + 1) % this.state.themes.length;
107
+ const nextTheme = this.state.themes[nextIndex];
108
+ this.setTheme(nextTheme.id);
109
+ }
110
+ _updateDOM() {
111
+ if (!this.container)
112
+ return;
113
+ const toggle = this.container.querySelector(`#${this._id}`);
114
+ if (!toggle)
115
+ return;
116
+ const currentTheme = this.state.themes.find(t => t.id === this.state.currentTheme);
117
+ if (!currentTheme)
118
+ return;
119
+ if (this.state.variant === 'button' || this.state.variant === 'cycle') {
120
+ const button = toggle.querySelector('button');
121
+ if (button && currentTheme.icon) {
122
+ button.innerHTML = '';
123
+ const iconElement = renderIcon(currentTheme.icon, currentTheme.iconCollection);
124
+ button.appendChild(iconElement);
125
+ if (this.state.showLabel) {
126
+ const labelSpan = document.createElement('span');
127
+ labelSpan.textContent = ` ${currentTheme.label}`;
128
+ button.appendChild(labelSpan);
129
+ }
130
+ requestAnimationFrame(() => {
131
+ if (window.Iconify) {
132
+ window.Iconify.scan();
133
+ }
134
+ });
135
+ }
136
+ }
137
+ if (this.state.variant === 'dropdown') {
138
+ const select = toggle.querySelector('select');
139
+ if (select) {
140
+ select.value = this.state.currentTheme;
141
+ }
142
+ }
143
+ }
144
+ /* ═════════════════════════════════════════════════════════════════
145
+ * RENDER
146
+ * ═════════════════════════════════════════════════════════════════ */
147
+ render(targetId) {
148
+ const container = this._setupContainer(targetId);
149
+ const { themes, currentTheme, showLabel, variant, style, class: className } = this.state;
150
+ const wrapper = document.createElement('div');
151
+ wrapper.className = `jux-theme-toggle`;
152
+ wrapper.id = this._id;
153
+ if (className) {
154
+ wrapper.className += ` ${className}`;
155
+ }
156
+ if (style) {
157
+ wrapper.setAttribute('style', style);
158
+ }
159
+ const theme = themes.find(t => t.id === currentTheme);
160
+ if (variant === 'button' || variant === 'cycle') {
161
+ const button = document.createElement('button');
162
+ button.className = 'jux-theme-toggle-button';
163
+ button.type = 'button';
164
+ button.setAttribute('aria-label', 'Toggle theme');
165
+ if (theme?.icon) {
166
+ const iconElement = renderIcon(theme.icon, theme.iconCollection);
167
+ button.appendChild(iconElement);
168
+ }
169
+ if (showLabel) {
170
+ const labelSpan = document.createElement('span');
171
+ labelSpan.textContent = ` ${theme?.label || currentTheme}`;
172
+ button.appendChild(labelSpan);
173
+ }
174
+ else if (!theme?.icon) {
175
+ button.textContent = theme?.label || currentTheme;
176
+ }
177
+ button.addEventListener('click', () => {
178
+ this.cycleTheme();
179
+ });
180
+ wrapper.appendChild(button);
181
+ }
182
+ else if (variant === 'dropdown') {
183
+ const select = document.createElement('select');
184
+ select.className = 'jux-theme-toggle-select';
185
+ select.setAttribute('aria-label', 'Select theme');
186
+ themes.forEach(t => {
187
+ const option = document.createElement('option');
188
+ option.value = t.id;
189
+ option.textContent = showLabel
190
+ ? `${t.icon || ''} ${t.label}`.trim()
191
+ : t.icon || t.label;
192
+ if (t.id === currentTheme) {
193
+ option.selected = true;
194
+ }
195
+ select.appendChild(option);
196
+ });
197
+ select.addEventListener('change', (e) => {
198
+ const target = e.target;
199
+ this.setTheme(target.value);
200
+ });
201
+ wrapper.appendChild(select);
202
+ }
203
+ this._wireStandardEvents(wrapper);
204
+ container.appendChild(wrapper);
205
+ requestAnimationFrame(() => {
206
+ if (window.Iconify) {
207
+ window.Iconify.scan();
208
+ }
209
+ });
210
+ return this;
211
+ }
212
+ }
213
+ export function themeToggle(id, options = {}) {
214
+ return new ThemeToggle(id, options);
215
+ }
@@ -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,30 @@
1
+ import { BaseComponent } from './base/BaseComponent.js';
2
+ export interface TooltipOptions {
3
+ text?: string;
4
+ position?: 'top' | 'bottom' | 'left' | 'right';
5
+ style?: string;
6
+ class?: string;
7
+ }
8
+ type TooltipState = {
9
+ text: string;
10
+ position: string;
11
+ style: string;
12
+ class: string;
13
+ };
14
+ export declare class Tooltip extends BaseComponent<TooltipState> {
15
+ private _tooltip;
16
+ private _target;
17
+ constructor(id: string, options?: TooltipOptions);
18
+ protected getTriggerEvents(): readonly string[];
19
+ protected getCallbackEvents(): readonly string[];
20
+ text(value: string): this;
21
+ position(value: 'top' | 'bottom' | 'left' | 'right'): this;
22
+ attachTo(target: HTMLElement | null): this;
23
+ private _setupTooltip;
24
+ private _show;
25
+ private _hide;
26
+ render(targetId?: string): this;
27
+ }
28
+ export declare function tooltip(id: string, options?: TooltipOptions): Tooltip;
29
+ export {};
30
+ //# sourceMappingURL=tooltip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["tooltip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAMxD,MAAM,WAAW,cAAc;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,KAAK,YAAY,GAAG;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,qBAAa,OAAQ,SAAQ,aAAa,CAAC,YAAY,CAAC;IACpD,OAAO,CAAC,QAAQ,CAA4B;IAC5C,OAAO,CAAC,OAAO,CAA4B;gBAE/B,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB;IASpD,SAAS,CAAC,gBAAgB,IAAI,SAAS,MAAM,EAAE;IAI/C,SAAS,CAAC,iBAAiB,IAAI,SAAS,MAAM,EAAE;IAQhD,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKzB,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI;IAK1D,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,GAAG,IAAI;IAY1C,OAAO,CAAC,aAAa;IA4BrB,OAAO,CAAC,KAAK;IAiCb,OAAO,CAAC,KAAK;IAMb,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;CAKlC;AAED,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAEzE"}
@@ -0,0 +1,109 @@
1
+ import { BaseComponent } from './base/BaseComponent.js';
2
+ // Event definitions
3
+ const TRIGGER_EVENTS = [];
4
+ const CALLBACK_EVENTS = [];
5
+ export class Tooltip extends BaseComponent {
6
+ constructor(id, options = {}) {
7
+ super(id, {
8
+ text: options.text ?? '',
9
+ position: options.position ?? 'top',
10
+ style: options.style ?? '',
11
+ class: options.class ?? ''
12
+ });
13
+ this._tooltip = null;
14
+ this._target = null;
15
+ }
16
+ getTriggerEvents() {
17
+ return TRIGGER_EVENTS;
18
+ }
19
+ getCallbackEvents() {
20
+ return CALLBACK_EVENTS;
21
+ }
22
+ /* ═════════════════════════════════════════════════════════════════
23
+ * FLUENT API
24
+ * ═════════════════════════════════════════════════════════════════ */
25
+ text(value) {
26
+ this.state.text = value;
27
+ return this;
28
+ }
29
+ position(value) {
30
+ this.state.position = value;
31
+ return this;
32
+ }
33
+ attachTo(target) {
34
+ if (!target)
35
+ return this;
36
+ this._target = target;
37
+ this._setupTooltip();
38
+ return this;
39
+ }
40
+ /* ═════════════════════════════════════════════════════════════════
41
+ * RENDER
42
+ * ═════════════════════════════════════════════════════════════════ */
43
+ _setupTooltip() {
44
+ if (!this._target)
45
+ return;
46
+ const { text, position, style, class: className } = this.state;
47
+ // Create tooltip element
48
+ const tooltip = document.createElement('div');
49
+ tooltip.className = `jux-tooltip jux-tooltip-${position}`;
50
+ tooltip.id = this._id;
51
+ if (className)
52
+ tooltip.className += ` ${className}`;
53
+ if (style)
54
+ tooltip.setAttribute('style', style);
55
+ tooltip.textContent = text;
56
+ tooltip.style.display = 'none';
57
+ this._tooltip = tooltip;
58
+ document.body.appendChild(tooltip);
59
+ // Show on hover
60
+ this._target.addEventListener('mouseenter', () => {
61
+ this._show();
62
+ });
63
+ this._target.addEventListener('mouseleave', () => {
64
+ this._hide();
65
+ });
66
+ }
67
+ _show() {
68
+ if (!this._tooltip || !this._target)
69
+ return;
70
+ const targetRect = this._target.getBoundingClientRect();
71
+ const tooltipRect = this._tooltip.getBoundingClientRect();
72
+ let top = 0;
73
+ let left = 0;
74
+ switch (this.state.position) {
75
+ case 'top':
76
+ top = targetRect.top - tooltipRect.height - 8;
77
+ left = targetRect.left + (targetRect.width - tooltipRect.width) / 2;
78
+ break;
79
+ case 'bottom':
80
+ top = targetRect.bottom + 8;
81
+ left = targetRect.left + (targetRect.width - tooltipRect.width) / 2;
82
+ break;
83
+ case 'left':
84
+ top = targetRect.top + (targetRect.height - tooltipRect.height) / 2;
85
+ left = targetRect.left - tooltipRect.width - 8;
86
+ break;
87
+ case 'right':
88
+ top = targetRect.top + (targetRect.height - tooltipRect.height) / 2;
89
+ left = targetRect.right + 8;
90
+ break;
91
+ }
92
+ this._tooltip.style.top = `${top}px`;
93
+ this._tooltip.style.left = `${left}px`;
94
+ this._tooltip.style.display = 'block';
95
+ }
96
+ _hide() {
97
+ if (this._tooltip) {
98
+ this._tooltip.style.display = 'none';
99
+ }
100
+ }
101
+ render(targetId) {
102
+ // Tooltips don't render to containers, they attach to targets
103
+ console.warn('Tooltip: Use .attachTo(element) instead of .render()');
104
+ return this;
105
+ }
106
+ }
107
+ export function tooltip(id, options = {}) {
108
+ return new Tooltip(id, options);
109
+ }