@spartan-ng/cli 1.10.0-beta.1 → 1.10.0-beta.3

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 (63) hide show
  1. package/generators.json +10 -0
  2. package/package.json +2 -2
  3. package/src/generators/base/lib/build-dependency-array.js +1 -1
  4. package/src/generators/base/lib/build-dependency-array.js.map +1 -1
  5. package/src/generators/base/lib/styles/transform-style-map.js +2 -2
  6. package/src/generators/base/lib/styles/transform-style-map.js.map +1 -1
  7. package/src/generators/base/versions.d.ts +1 -1
  8. package/src/generators/base/versions.js +3 -2
  9. package/src/generators/base/versions.js.map +1 -1
  10. package/src/generators/healthcheck/generator.d.ts +1 -1
  11. package/src/generators/healthcheck/generator.js +4 -0
  12. package/src/generators/healthcheck/generator.js.map +1 -1
  13. package/src/generators/healthcheck/healthchecks/cn.d.ts +2 -0
  14. package/src/generators/healthcheck/healthchecks/cn.js +34 -0
  15. package/src/generators/healthcheck/healthchecks/cn.js.map +1 -0
  16. package/src/generators/migrate-cn/compat.d.ts +2 -0
  17. package/src/generators/migrate-cn/compat.js +7 -0
  18. package/src/generators/migrate-cn/compat.js.map +1 -0
  19. package/src/generators/migrate-cn/generator.d.ts +10 -0
  20. package/src/generators/migrate-cn/generator.js +220 -0
  21. package/src/generators/migrate-cn/generator.js.map +1 -0
  22. package/src/generators/migrate-cn/lib/legacy-imports.d.ts +9 -0
  23. package/src/generators/migrate-cn/lib/legacy-imports.js +16 -0
  24. package/src/generators/migrate-cn/lib/legacy-imports.js.map +1 -0
  25. package/src/generators/migrate-cn/lib/source-fingerprint.d.ts +6 -0
  26. package/src/generators/migrate-cn/lib/source-fingerprint.js +46 -0
  27. package/src/generators/migrate-cn/lib/source-fingerprint.js.map +1 -0
  28. package/src/generators/migrate-cn/schema.d.ts +3 -0
  29. package/src/generators/migrate-cn/schema.json +14 -0
  30. package/src/generators/ui/libs/accordion/files/lib/hlm-accordion-trigger.ts.template +1 -1
  31. package/src/generators/ui/libs/alert-dialog/files/lib/hlm-alert-dialog-overlay.ts.template +1 -1
  32. package/src/generators/ui/libs/button/files/lib/hlm-button.ts.template +1 -1
  33. package/src/generators/ui/libs/carousel/files/lib/hlm-carousel-slide-display.ts.template +1 -1
  34. package/src/generators/ui/libs/checkbox/files/lib/hlm-checkbox.ts.template +1 -1
  35. package/src/generators/ui/libs/combobox/files/lib/hlm-combobox-trigger.ts.template +1 -1
  36. package/src/generators/ui/libs/command/files/lib/hlm-command-dialog.ts.template +1 -1
  37. package/src/generators/ui/libs/date-picker/files/lib/hlm-date-picker-trigger.ts.template +1 -1
  38. package/src/generators/ui/libs/dialog/files/lib/hlm-dialog-overlay.ts.template +1 -1
  39. package/src/generators/ui/libs/drawer/files/lib/hlm-drawer-overlay.ts.template +1 -1
  40. package/src/generators/ui/libs/input-otp/files/lib/hlm-input-otp.ts.template +1 -1
  41. package/src/generators/ui/libs/native-select/files/lib/hlm-native-select.ts.template +1 -1
  42. package/src/generators/ui/libs/pagination/files/lib/hlm-numbered-pagination-query-params.ts.template +15 -2
  43. package/src/generators/ui/libs/pagination/files/lib/hlm-numbered-pagination.ts.template +79 -7
  44. package/src/generators/ui/libs/pagination/files/lib/hlm-pagination-next.ts.template +27 -13
  45. package/src/generators/ui/libs/pagination/files/lib/hlm-pagination-previous.ts.template +27 -13
  46. package/src/generators/ui/libs/pagination/files/lib/hlm-pagination.token.ts.template +2 -0
  47. package/src/generators/ui/libs/radio-group/files/lib/hlm-radio-group.ts.template +1 -1
  48. package/src/generators/ui/libs/radio-group/files/lib/hlm-radio.ts.template +1 -1
  49. package/src/generators/ui/libs/select/files/lib/hlm-select-trigger.ts.template +1 -1
  50. package/src/generators/ui/libs/sheet/files/lib/hlm-sheet-overlay.ts.template +1 -1
  51. package/src/generators/ui/libs/sidebar/files/lib/hlm-sidebar.ts.template +1 -1
  52. package/src/generators/ui/libs/sonner/files/lib/hlm-toaster.ts.template +1 -1
  53. package/src/generators/ui/libs/switch/files/lib/hlm-switch.ts.template +1 -1
  54. package/src/generators/ui/libs/tabs/files/lib/hlm-tabs-paginated-list.ts.template +1 -1
  55. package/src/generators/ui/libs/trace/files/lib/hlm-trace-collapsible-content.ts.template +1 -1
  56. package/src/generators/ui/libs/utils/files/lib/hlm.ts.template +20 -302
  57. package/src/generators/ui/supported-ui-libraries.json +68 -70
  58. package/src/utils/config.d.ts +1 -0
  59. package/src/utils/config.js +7 -0
  60. package/src/utils/config.js.map +1 -1
  61. package/src/utils/version-utils.d.ts +1 -1
  62. package/src/utils/version-utils.js +3 -2
  63. package/src/utils/version-utils.js.map +1 -1
@@ -1,309 +1,27 @@
1
- import { isPlatformBrowser } from '@angular/common';
2
- import {
3
- DestroyRef,
4
- effect,
5
- ElementRef,
6
- HostAttributeToken,
7
- inject,
8
- Injector,
9
- NgZone,
10
- PLATFORM_ID,
11
- runInInjectionContext,
12
- } from '@angular/core';
13
- import { type ClassValue, clsx } from 'clsx';
14
- import { twMerge } from 'tailwind-merge';
1
+ import { brnClasses, type BrnClassesOptions } from '@spartan-ng/brain/core';
2
+ import { type ClassValue, cn } from 'cn';
15
3
 
16
- export function hlm(...inputs: ClassValue[]) {
17
- return twMerge(clsx(inputs));
18
- }
19
-
20
- // Global map to track class managers per element
21
- const elementClassManagers = new WeakMap<HTMLElement, ElementClassManager>();
22
- // Global mutation observer for all elements
23
- let globalObserver: MutationObserver | null = null;
24
- const observedElements = new Set<HTMLElement>();
25
-
26
- interface ElementClassManager {
27
- element: HTMLElement;
28
- sources: Map<number, { classes: Set<string>; order: number }>;
29
- baseClasses: Set<string>;
30
- isUpdating: boolean;
31
- nextOrder: number;
32
- hasInitialized: boolean;
33
- restoreRafId: number | null;
34
- /** Transitions are suppressed until the first effect writes correct classes */
35
- transitionsSuppressed: boolean;
36
- /** Original inline transition value to restore after suppression (empty string = none was set) */
37
- previousTransition: string;
38
- /** Original inline transition priority to preserve !important when restoring */
39
- previousTransitionPriority: string;
40
- }
41
-
42
- let sourceCounter = 0;
4
+ /**
5
+ * Merges class values and resolves Tailwind CSS conflicts.
6
+ *
7
+ * To customize the merge (e.g. register custom theme values), create your own instance:
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { createCn } from 'cn/config';
12
+ *
13
+ * export const hlm = createCn({
14
+ * extend: { classGroups: { 'font-size': [{ text: ['hero'] }] } },
15
+ * });
16
+ * ```
17
+ */
18
+ export const hlm = cn;
43
19
 
44
20
  /**
45
21
  * This function dynamically adds and removes classes for a given element without requiring
46
22
  * the a class binding (e.g. `[class]="..."`) which may interfere with other class bindings.
47
- *
48
- * 1. This will merge the existing classes on the element with the new classes.
49
- * 2. It will also remove any classes that were previously added by this function but are no longer present in the new classes.
50
- * 3. Multiple calls to this function on the same element will be merged efficiently.
23
+ * The classes are merged with `hlm`.
51
24
  */
52
- export function classes(computed: () => ClassValue[] | string, options: ClassesOptions = {}) {
53
- runInInjectionContext(options.injector ?? inject(Injector), () => {
54
- const elementRef = options.elementRef ?? inject(ElementRef);
55
- const platformId = inject(PLATFORM_ID);
56
- const destroyRef = inject(DestroyRef);
57
- const baseClasses = inject(new HostAttributeToken('class'), { optional: true });
58
-
59
- const element = elementRef.nativeElement;
60
-
61
- // Create unique identifier for this source
62
- const sourceId = sourceCounter++;
63
-
64
- // Get or create the class manager for this element
65
- let manager = elementClassManagers.get(element);
66
-
67
- if (!manager) {
68
- // Initialize base classes from variation (host attribute 'class')
69
- const initialBaseClasses = new Set<string>();
70
-
71
- if (baseClasses) {
72
- toClassList(baseClasses).forEach((cls) => initialBaseClasses.add(cls));
73
- }
74
-
75
- manager = {
76
- element,
77
- sources: new Map(),
78
- baseClasses: initialBaseClasses,
79
- isUpdating: false,
80
- nextOrder: 0,
81
- hasInitialized: false,
82
- restoreRafId: null,
83
- transitionsSuppressed: false,
84
- previousTransition: '',
85
- previousTransitionPriority: '',
86
- };
87
- elementClassManagers.set(element, manager);
88
-
89
- // Setup global observer if needed and register this element. Created outside the zone so
90
- // class mutations don't trigger app-wide change detection (and loop if CD writes a class).
91
- inject(NgZone).runOutsideAngular(() => setupGlobalObserver(platformId));
92
- observedElements.add(element);
93
-
94
- // Suppress transitions until the first effect writes correct classes and
95
- // the browser has painted them. This prevents CSS transition animations
96
- // during hydration when classes change from SSR state to client state.
97
- if (isPlatformBrowser(platformId)) {
98
- manager.previousTransition = element.style.getPropertyValue('transition');
99
- manager.previousTransitionPriority = element.style.getPropertyPriority('transition');
100
- element.style.setProperty('transition', 'none', 'important');
101
- manager.transitionsSuppressed = true;
102
- }
103
- }
104
-
105
- // Assign order once at registration time
106
- const sourceOrder = manager.nextOrder++;
107
-
108
- function updateClasses(): void {
109
- // Get the new classes from the computed function
110
- const newClasses = toClassList(computed());
111
-
112
- // Update this source's classes, keeping the original order
113
- manager!.sources.set(sourceId, {
114
- classes: new Set(newClasses),
115
- order: sourceOrder,
116
- });
117
-
118
- // Update the element
119
- updateElement(manager!);
120
-
121
- // Re-enable transitions after the first effect writes correct classes.
122
- // Deferred to next animation frame so the browser paints the class change
123
- // with transitions disabled first, then re-enables them.
124
- if (manager!.transitionsSuppressed) {
125
- manager!.transitionsSuppressed = false;
126
- manager!.restoreRafId = requestAnimationFrame(() => {
127
- manager!.restoreRafId = null;
128
- restoreTransitionSuppression(manager!);
129
- });
130
- }
131
- }
132
-
133
- // Register cleanup with DestroyRef
134
- destroyRef.onDestroy(() => {
135
- if (manager!.restoreRafId !== null) {
136
- cancelAnimationFrame(manager!.restoreRafId);
137
- manager!.restoreRafId = null;
138
- }
139
-
140
- if (manager!.transitionsSuppressed) {
141
- manager!.transitionsSuppressed = false;
142
- restoreTransitionSuppression(manager!);
143
- }
144
-
145
- // Remove this source from the manager
146
- manager!.sources.delete(sourceId);
147
-
148
- // If no more sources, clean up the manager
149
- if (manager!.sources.size === 0) {
150
- cleanupManager(element);
151
- } else {
152
- // Update element without this source's classes
153
- updateElement(manager!);
154
- }
155
- });
156
-
157
- /**
158
- * We need this effect to track changes to the computed classes. Ideally, we would use
159
- * afterRenderEffect here, but that doesn't run in SSR contexts, so we use a standard
160
- * effect which works in both browser and SSR.
161
- */
162
- effect(updateClasses);
163
- });
164
- }
165
-
166
- function restoreTransitionSuppression(manager: ElementClassManager): void {
167
- const prev = manager.previousTransition;
168
- if (prev) {
169
- manager.element.style.setProperty('transition', prev, manager.previousTransitionPriority || undefined);
170
- } else {
171
- manager.element.style.removeProperty('transition');
172
- }
173
- }
174
-
175
- // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
176
- function setupGlobalObserver(platformId: Object): void {
177
- if (isPlatformBrowser(platformId) && !globalObserver) {
178
- // Create single global observer that watches the entire document
179
- globalObserver = new MutationObserver((mutations) => {
180
- for (const mutation of mutations) {
181
- if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
182
- const element = mutation.target as HTMLElement;
183
- const manager = elementClassManagers.get(element);
184
-
185
- // Only process elements we're managing
186
- if (manager && observedElements.has(element)) {
187
- if (manager.isUpdating) continue; // Ignore changes we're making
188
-
189
- // Update base classes to include any externally added classes
190
- const currentClasses = toClassList(element.className);
191
- const allSourceClasses = new Set<string>();
192
-
193
- // Collect all classes from all sources
194
- for (const source of manager.sources.values()) {
195
- for (const className of source.classes) {
196
- allSourceClasses.add(className);
197
- }
198
- }
199
-
200
- // Any classes not from sources become new base classes
201
- manager.baseClasses.clear();
202
-
203
- for (const className of currentClasses) {
204
- if (!allSourceClasses.has(className)) {
205
- manager.baseClasses.add(className);
206
- }
207
- }
208
-
209
- updateElement(manager);
210
- }
211
- }
212
- }
213
- });
214
-
215
- // Start observing the entire document for class attribute changes
216
- globalObserver.observe(document, {
217
- attributes: true,
218
- attributeFilter: ['class'],
219
- subtree: true, // Watch all descendants
220
- });
221
- }
222
- }
223
-
224
- function updateElement(manager: ElementClassManager): void {
225
- if (manager.isUpdating) return; // Prevent recursive updates
226
-
227
- manager.isUpdating = true;
228
-
229
- // Handle initialization: capture base classes after first source registration
230
- if (!manager.hasInitialized && manager.sources.size > 0) {
231
- // Get current classes on element (may include SSR classes)
232
- const currentClasses = toClassList(manager.element.className);
233
-
234
- // Get all classes that will be applied by sources
235
- const allSourceClasses = new Set<string>();
236
- for (const source of manager.sources.values()) {
237
- source.classes.forEach((className) => allSourceClasses.add(className));
238
- }
239
-
240
- // Only consider classes as "base" if they're not produced by any source
241
- // This prevents SSR-rendered classes from being preserved as base classes
242
- currentClasses.forEach((className) => {
243
- if (!allSourceClasses.has(className)) {
244
- manager.baseClasses.add(className);
245
- }
246
- });
247
-
248
- manager.hasInitialized = true;
249
- }
250
-
251
- // Get classes from all sources, sorted by registration order (later takes precedence)
252
- const sortedSources = Array.from(manager.sources.entries()).sort(([, a], [, b]) => a.order - b.order);
253
-
254
- const allSourceClasses: string[] = [];
255
- for (const [, source] of sortedSources) {
256
- allSourceClasses.push(...source.classes);
257
- }
258
-
259
- // Combine base classes with all source classes, ensuring base classes take precedence
260
- const classesToApply =
261
- allSourceClasses.length > 0 || manager.baseClasses.size > 0
262
- ? hlm([...allSourceClasses, ...manager.baseClasses])
263
- : '';
264
-
265
- // Apply the classes to the element
266
- if (manager.element.className !== classesToApply) {
267
- manager.element.className = classesToApply;
268
- }
269
-
270
- manager.isUpdating = false;
271
- }
272
-
273
- function cleanupManager(element: HTMLElement): void {
274
- // Remove from global tracking
275
- observedElements.delete(element);
276
- elementClassManagers.delete(element);
277
-
278
- // If no more elements being tracked, cleanup global observer
279
- if (observedElements.size === 0 && globalObserver) {
280
- globalObserver.disconnect();
281
- globalObserver = null;
282
- }
283
- }
284
-
285
- interface ClassesOptions {
286
- elementRef?: ElementRef<HTMLElement>;
287
- injector?: Injector;
288
- }
289
-
290
- // Cache for parsed class lists to avoid repeated string operations
291
- const classListCache = new Map<string, string[]>();
292
-
293
- function toClassList(className: string | ClassValue[]): string[] {
294
- // For simple string inputs, use cache to avoid repeated parsing
295
- if (typeof className === 'string' && classListCache.has(className)) {
296
- return classListCache.get(className)!;
297
- }
298
-
299
- const result = clsx(className)
300
- .split(' ')
301
- .filter((c) => c.length > 0);
302
-
303
- // Cache string results, but limit cache size to prevent memory growth
304
- if (typeof className === 'string' && classListCache.size < 1000) {
305
- classListCache.set(className, result);
306
- }
307
-
308
- return result;
25
+ export function classes(computed: () => ClassValue[] | string, options: Omit<BrnClassesOptions, 'merge'> = {}) {
26
+ brnClasses(computed, { ...options, merge: hlm });
309
27
  }