@masterteam/components 0.0.45 → 0.0.47

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.
@@ -73,71 +73,86 @@ function hslToHex(h, s, l) {
73
73
  return `#${f(0)}${f(8)}${f(4)}`;
74
74
  }
75
75
  /**
76
- * Generates a Tailwind-like color palette (50-950) from a primary color (assumed to be 500).
76
+ * Defines the "ideal" lightness and saturation adjustment for each shade.
77
+ * Lightness for 500 is set to 50 as a balanced default.
78
+ */
79
+ const PALETTE_PROFILE = {
80
+ '0': { l: 98, s_adjust: -50 },
81
+ '50': { l: 95, s_adjust: -40 },
82
+ '100': { l: 90, s_adjust: -30 },
83
+ '200': { l: 80, s_adjust: -20 },
84
+ '300': { l: 70, s_adjust: -10 },
85
+ '400': { l: 60, s_adjust: -5 },
86
+ '500': { l: 50, s_adjust: 0 },
87
+ '600': { l: 45, s_adjust: 5 },
88
+ '700': { l: 35, s_adjust: 10 },
89
+ '800': { l: 25, s_adjust: 15 },
90
+ '900': { l: 15, s_adjust: 20 },
91
+ '950': { l: 8, s_adjust: 25 },
92
+ };
93
+ // Helper to ensure palette is always in the correct 50-950 order
94
+ const ALL_SHADES = [
95
+ '0',
96
+ '50',
97
+ '100',
98
+ '200',
99
+ '300',
100
+ '400',
101
+ '500',
102
+ '600',
103
+ '700',
104
+ '800',
105
+ '900',
106
+ '950',
107
+ ];
108
+ /**
109
+ * Clamps a number between a min and max value.
110
+ */
111
+ function clamp(value, min, max) {
112
+ return Math.max(min, Math.min(max, value));
113
+ }
114
+ /**
115
+ * Generates a Tailwind-like color palette (50-950) from any given base color.
77
116
  *
78
- * @param primaryColor500 - The hex string of the primary color (e.g., "#0284c7").
79
- * @returns An object representing the color palette, where keys are color numbers (e.g., "50", "100")
80
- * and values are hex color strings.
117
+ * @param baseColorHex - The hex string of the base color (e.g., "#0284c7").
118
+ * @param baseColorShade - The shade of the base color (e.g., "500", "700").
119
+ * @returns An object representing the full color palette.
81
120
  */
82
- function generateTailwindPalette(primaryColor500) {
83
- const [h, s, _l] = hexToHsl(primaryColor500);
84
- const palette = {
85
- '500': primaryColor500,
86
- };
87
- // Define steps for lighter shades (50 - 400)
88
- const lightnessStepsLighter = {
89
- '50': 95,
90
- '100': 90,
91
- '200': 80,
92
- '300': 70,
93
- '400': 60,
94
- };
95
- const saturationReductionsLighter = {
96
- '50': 40, // More desaturated
97
- '100': 30,
98
- '200': 20,
99
- '300': 10,
100
- '400': 5, // Slightly desaturated
101
- };
102
- for (const shade in lightnessStepsLighter) {
103
- if (Object.prototype.hasOwnProperty.call(lightnessStepsLighter, shade)) {
104
- const newL = lightnessStepsLighter[shade];
105
- // Ensure saturation doesn't go below 0
106
- const newS = Math.max(0, s - saturationReductionsLighter[shade]);
107
- palette[shade] = hslToHex(h, newS, newL);
108
- }
109
- }
110
- // Define steps for darker shades (600 - 950)
111
- const lightnessStepsDarker = {
112
- '600': 45,
113
- '700': 35,
114
- '800': 25,
115
- '900': 15,
116
- '950': 8, // More aggressive darkening for 950
117
- };
118
- const saturationIncreasesDarker = {
119
- '600': 5,
120
- '700': 10,
121
- '800': 15,
122
- '900': 20,
123
- '950': 25, // Can increase saturation for darker shades
124
- };
125
- for (const shade in lightnessStepsDarker) {
126
- if (Object.prototype.hasOwnProperty.call(lightnessStepsDarker, shade)) {
127
- const newL = lightnessStepsDarker[shade];
128
- // Ensure saturation doesn't exceed 100
129
- const newS = Math.min(100, s + saturationIncreasesDarker[shade]);
130
- palette[shade] = hslToHex(h, newS, newL);
131
- }
132
- }
133
- // Sort the keys numerically to ensure consistent order
134
- const sortedPalette = {};
135
- Object.keys(palette)
136
- .sort((a, b) => parseInt(a) - parseInt(b))
137
- .forEach((key) => {
138
- sortedPalette[key] = palette[key];
139
- });
140
- return sortedPalette;
121
+ function generateTailwindPalette(baseColorHex, baseColorShade = '500') {
122
+ // 1. Get HSL of the input color
123
+ const [h_base, s_base, l_base] = hexToHsl(baseColorHex);
124
+ // 2. Find the anchors
125
+ const baseProfile = PALETTE_PROFILE[baseColorShade];
126
+ /** The Hue is constant across the entire palette. */
127
+ const h = h_base;
128
+ /**
129
+ * Calculate the 500-shade's saturation by "reversing" the adjustment
130
+ * from the base color.
131
+ * e.g., if base is 700 (s_adjust: +10) and s_base is 80,
132
+ * s_500 will be 70.
133
+ */
134
+ const s_500 = clamp(s_base - baseProfile.s_adjust, 0, 100);
135
+ /**
136
+ * Calculate the lightness "offset". This is the difference between
137
+ * the base color's actual lightness and its "ideal" lightness
138
+ * from the profile.
139
+ * e.g., if base is 700 (ideal L: 35) and l_base is 38,
140
+ * the offset is +3. This offset will be applied to all shades.
141
+ */
142
+ const l_offset = l_base - baseProfile.l;
143
+ // 3. Generate the full palette
144
+ const palette = {};
145
+ for (const shade of ALL_SHADES) {
146
+ const profile = PALETTE_PROFILE[shade];
147
+ // Calculate the new saturation and lightness for this shade
148
+ const newS = clamp(s_500 + profile.s_adjust, 0, 100);
149
+ const newL = clamp(profile.l + l_offset, 0, 100);
150
+ palette[shade] = hslToHex(h, newS, newL);
151
+ }
152
+ // 4. Ensure the originally provided color is used exactly
153
+ // (to avoid rounding errors from HSL conversion)
154
+ palette[baseColorShade] = baseColorHex;
155
+ return palette;
141
156
  }
142
157
 
143
158
  const toastStyle = {
@@ -158,111 +173,164 @@ function changePrimaryColor(color) {
158
173
  },
159
174
  });
160
175
  }
161
- const MTPreset = (primaryColor) => definePreset(Aura, {
162
- options: {
163
- prefix: 'mt',
164
- cssLayer: {
165
- name: 'primeng',
166
- order: 'theme, base, primeng',
167
- },
168
- },
169
- semantic: {
170
- primary: generateTailwindPalette(primaryColor || '#334dff'),
171
- content: {
172
- borderRadius: '{border.radius.lg}',
173
- },
174
- formField: {
175
- borderRadius: '{border.radius.lg}',
176
- },
177
- },
178
- components: {
179
- dialog: {
180
- header: {
181
- padding: '0',
182
- },
183
- content: {
184
- padding: '0',
185
- },
186
- footer: {
187
- padding: '0',
188
- },
189
- },
190
- toast: {
191
- root: {
192
- borderRadius: '{border.radius.xl}',
193
- },
176
+ function changeBackgroundColor(color) {
177
+ if (color) {
178
+ const palette = generateTailwindPalette(color, '100');
179
+ console.log('the background palette', palette);
180
+ document.documentElement.style.setProperty('--app-background-light', palette['100']);
181
+ document.documentElement.style.setProperty('--app-background-dark', palette['950']);
182
+ }
183
+ }
184
+ function changeTextColor(color) {
185
+ const palette = generateTailwindPalette(color ?? '#334155', '700');
186
+ updatePreset({
187
+ semantic: {
194
188
  colorScheme: {
195
189
  light: {
196
- success: toastStyle,
197
- info: toastStyle,
198
- warn: toastStyle,
199
- error: toastStyle,
200
- secondary: toastStyle,
190
+ text: {
191
+ color: palette['700'],
192
+ hoverColor: palette['800'],
193
+ hoverMutedColor: palette['600'],
194
+ mutedColor: palette['500'],
195
+ },
201
196
  },
202
197
  dark: {
203
- success: toastStyle,
204
- info: toastStyle,
205
- warn: toastStyle,
206
- error: toastStyle,
207
- secondary: toastStyle,
198
+ text: {
199
+ color: palette['0'],
200
+ hoverColor: palette['0'],
201
+ hoverMutedColor: palette['300'],
202
+ mutedColor: palette['400'],
203
+ },
208
204
  },
209
205
  },
210
206
  },
211
- togglebutton: {
212
- root: {
213
- padding: '1px',
207
+ });
208
+ }
209
+ const MTPreset = (themeOptions) => {
210
+ const textPalette = generateTailwindPalette(themeOptions?.textColor ?? '#334155', '700');
211
+ const configs = {
212
+ options: {
213
+ prefix: 'mt',
214
+ cssLayer: {
215
+ name: 'primeng',
216
+ order: 'theme, base, primeng',
214
217
  },
218
+ },
219
+ semantic: {
215
220
  colorScheme: {
216
221
  light: {
217
- root: {
218
- checkedColor: '{primary.500}',
222
+ text: {
223
+ color: textPalette['700'],
224
+ hoverColor: textPalette['800'],
225
+ hoverMutedColor: textPalette['600'],
226
+ mutedColor: textPalette['500'],
219
227
  },
220
228
  },
221
229
  dark: {
222
- root: {
223
- checkedColor: '{primary.400}',
230
+ text: {
231
+ color: textPalette['0'],
232
+ hoverColor: textPalette['0'],
233
+ hoverMutedColor: textPalette['300'],
234
+ mutedColor: textPalette['400'],
224
235
  },
225
236
  },
226
237
  },
227
- },
228
- selectbutton: {
229
- root: {
238
+ primary: generateTailwindPalette(themeOptions?.primaryColor || '#334dff'),
239
+ content: {
230
240
  borderRadius: '{border.radius.lg}',
231
241
  },
232
- },
233
- paginator: {
234
- root: {
242
+ formField: {
235
243
  borderRadius: '{border.radius.lg}',
236
- padding: '0 .5rem',
237
244
  },
238
- navButton: {
239
- borderRadius: '0',
245
+ },
246
+ components: {
247
+ dialog: {
248
+ header: {
249
+ padding: '0',
250
+ },
251
+ content: {
252
+ padding: '0',
253
+ },
254
+ footer: {
255
+ padding: '0',
256
+ },
240
257
  },
241
- colorScheme: {
242
- light: {
243
- navButton: {
244
- color: '{surface.600}',
245
- hoverBackground: '#fff',
246
- selectedBackground: '{surface.200}',
247
- selectedColor: '{surface.600}',
248
- focusRing: {
249
- color: '{surface.200}',
250
- },
258
+ toast: {
259
+ root: {
260
+ borderRadius: '{border.radius.xl}',
261
+ },
262
+ colorScheme: {
263
+ light: {
264
+ success: toastStyle,
265
+ info: toastStyle,
266
+ warn: toastStyle,
267
+ error: toastStyle,
268
+ secondary: toastStyle,
269
+ },
270
+ dark: {
271
+ success: toastStyle,
272
+ info: toastStyle,
273
+ warn: toastStyle,
274
+ error: toastStyle,
275
+ secondary: toastStyle,
251
276
  },
252
277
  },
253
- dark: {
254
- navButton: {
255
- color: '{surface.200}',
256
- hoverBackground: 'transparent',
257
- selectedBackground: 'transparent',
258
- selectedColor: '#fff',
259
- focusRing: {
260
- color: '#fff',
278
+ },
279
+ togglebutton: {
280
+ root: {
281
+ padding: '1px',
282
+ },
283
+ colorScheme: {
284
+ light: {
285
+ root: {
286
+ checkedColor: '{primary.500}',
287
+ },
288
+ },
289
+ dark: {
290
+ root: {
291
+ checkedColor: '{primary.400}',
261
292
  },
262
293
  },
263
294
  },
264
295
  },
265
- css: () => `
296
+ selectbutton: {
297
+ root: {
298
+ borderRadius: '{border.radius.lg}',
299
+ },
300
+ },
301
+ paginator: {
302
+ root: {
303
+ borderRadius: '{border.radius.lg}',
304
+ padding: '0 .5rem',
305
+ },
306
+ navButton: {
307
+ borderRadius: '0',
308
+ },
309
+ colorScheme: {
310
+ light: {
311
+ navButton: {
312
+ color: '{surface.600}',
313
+ hoverBackground: '#fff',
314
+ selectedBackground: '{surface.200}',
315
+ selectedColor: '{surface.600}',
316
+ focusRing: {
317
+ color: '{surface.200}',
318
+ },
319
+ },
320
+ },
321
+ dark: {
322
+ navButton: {
323
+ color: '{surface.200}',
324
+ hoverBackground: 'transparent',
325
+ selectedBackground: 'transparent',
326
+ selectedColor: '#fff',
327
+ focusRing: {
328
+ color: '#fff',
329
+ },
330
+ },
331
+ },
332
+ },
333
+ css: () => `
266
334
  .p-paginator {
267
335
  --p-paginator-gap: 0;
268
336
  --p-paginator-nav-button-width: 2.2rem;
@@ -324,35 +392,38 @@ const MTPreset = (primaryColor) => definePreset(Aura, {
324
392
  border-left-color: var(--p-surface-500);
325
393
  }
326
394
  `,
327
- },
328
- toggleswitch: {
329
- root: {
330
- width: '2.5rem',
331
- height: '1.4rem',
332
395
  },
396
+ toggleswitch: {
397
+ root: {
398
+ width: '2.5rem',
399
+ height: '1.4rem',
400
+ },
401
+ },
402
+ // steps: {
403
+ // item: {
404
+ // link: {
405
+ // gap: 'calc(50% + 0.25rem)',
406
+ // },
407
+ // number: {
408
+ // font: {
409
+ // size: '0.9rem',
410
+ // },
411
+ // active: {
412
+ // color: 'white',
413
+ // background: '{primary.500}',
414
+ // border: {
415
+ // color: '{primary.500}',
416
+ // },
417
+ // },
418
+ // },
419
+ // },
420
+ // },
333
421
  },
334
- // steps: {
335
- // item: {
336
- // link: {
337
- // gap: 'calc(50% + 0.25rem)',
338
- // },
339
- // number: {
340
- // font: {
341
- // size: '0.9rem',
342
- // },
343
- // active: {
344
- // color: 'white',
345
- // background: '{primary.500}',
346
- // border: {
347
- // color: '{primary.500}',
348
- // },
349
- // },
350
- // },
351
- // },
352
- // },
353
- },
354
- });
355
- function provideMTComponents(primaryColor) {
422
+ };
423
+ return definePreset(Aura, configs);
424
+ };
425
+ function provideMTComponents(themeOptions) {
426
+ changeBackgroundColor(themeOptions?.backgroundColor);
356
427
  return providePrimeNG({
357
428
  zIndex: {
358
429
  modal: 1900,
@@ -361,7 +432,7 @@ function provideMTComponents(primaryColor) {
361
432
  tooltip: 1600,
362
433
  },
363
434
  theme: {
364
- preset: MTPreset(primaryColor),
435
+ preset: MTPreset(themeOptions),
365
436
  options: {
366
437
  darkModeSelector: '.dark',
367
438
  },
@@ -830,5 +901,5 @@ function wrapValidatorWithMessage(validator, errorKey, message) {
830
901
  * Generated bundle index. Do not edit.
831
902
  */
832
903
 
833
- export { BaseFieldConfig, CheckboxFieldConfig, ColorPickerFieldConfig, DateFieldConfig, EditorFieldConfig, IconFieldConfig, MultiSelectFieldConfig, NumberFieldConfig, PickListFieldConfig, RadioButtonFieldConfig, RadioCardsFieldConfig, SelectFieldConfig, SliderFieldConfig, SpacerFieldConfig, TextFieldConfig, TextareaFieldConfig, ToggleFieldConfig, UploadFileFieldConfig, UserSearchFieldConfig, ValidatorConfig, changePrimaryColor, createCustomValidator, generateTailwindPalette, isInvalid, provideMTComponents, provideMTMessages, wrapValidatorWithMessage };
904
+ export { BaseFieldConfig, CheckboxFieldConfig, ColorPickerFieldConfig, DateFieldConfig, EditorFieldConfig, IconFieldConfig, MultiSelectFieldConfig, NumberFieldConfig, PickListFieldConfig, RadioButtonFieldConfig, RadioCardsFieldConfig, SelectFieldConfig, SliderFieldConfig, SpacerFieldConfig, TextFieldConfig, TextareaFieldConfig, ToggleFieldConfig, UploadFileFieldConfig, UserSearchFieldConfig, ValidatorConfig, changeBackgroundColor, changePrimaryColor, changeTextColor, createCustomValidator, generateTailwindPalette, isInvalid, provideMTComponents, provideMTMessages, wrapValidatorWithMessage };
834
905
  //# sourceMappingURL=masterteam-components.mjs.map