@masterteam/components 0.0.268 → 0.0.269

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.
@@ -161,156 +161,6 @@ function generateTailwindPalette(baseColorHex, baseColorShade = '500') {
161
161
  return palette;
162
162
  }
163
163
 
164
- /**
165
- * Color utility functions for brand display.
166
- */
167
- /**
168
- * Converts a hex color to a light shade (equivalent to primary-100 in Tailwind).
169
- * This creates a color with ~10% opacity or a very light tint by mixing with white.
170
- */
171
- function getLightColor(hexColor) {
172
- const hex = hexColor.replace('#', '');
173
- const r = parseInt(hex.substring(0, 2), 16);
174
- const g = parseInt(hex.substring(2, 4), 16);
175
- const b = parseInt(hex.substring(4, 6), 16);
176
- const lightR = Math.round(r * 0.1 + 255 * 0.9);
177
- const lightG = Math.round(g * 0.1 + 255 * 0.9);
178
- const lightB = Math.round(b * 0.1 + 255 * 0.9);
179
- return `#${lightR.toString(16).padStart(2, '0')}${lightG
180
- .toString(16)
181
- .padStart(2, '0')}${lightB.toString(16).padStart(2, '0')}`;
182
- }
183
- function getContrastColor(bgColor) {
184
- let r = 0, g = 0, b = 0;
185
- if (bgColor.startsWith('#')) {
186
- const hex = bgColor.slice(1);
187
- if (hex.length === 3) {
188
- r = parseInt(hex[0] + hex[0], 16);
189
- g = parseInt(hex[1] + hex[1], 16);
190
- b = parseInt(hex[2] + hex[2], 16);
191
- }
192
- else if (hex.length === 6) {
193
- r = parseInt(hex.slice(0, 2), 16);
194
- g = parseInt(hex.slice(2, 4), 16);
195
- b = parseInt(hex.slice(4, 6), 16);
196
- }
197
- }
198
- const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
199
- return luminance > 0.5 ? '' : '#ffffff';
200
- }
201
- /** Parses `#rgb` / `#rrggbb` into 0-255 channels. Null when unparseable. */
202
- function toRgb(hex) {
203
- const value = hex.trim().replace('#', '');
204
- const full = value.length === 3
205
- ? value
206
- .split('')
207
- .map((c) => c + c)
208
- .join('')
209
- : value;
210
- if (full.length !== 6 || !/^[0-9a-f]{6}$/i.test(full)) {
211
- return null;
212
- }
213
- return [
214
- parseInt(full.slice(0, 2), 16),
215
- parseInt(full.slice(2, 4), 16),
216
- parseInt(full.slice(4, 6), 16),
217
- ];
218
- }
219
- /**
220
- * WCAG 2.x relative luminance.
221
- *
222
- * Note this is NOT the 0.299/0.587/0.114 perceived-brightness formula used by
223
- * `getContrastColor` above — that one is fine for "is this light or dark?" but
224
- * it is not the definition a conformance ratio is measured against, so it
225
- * cannot be used to decide whether text passes AA.
226
- */
227
- function relativeLuminance(hex) {
228
- const rgb = toRgb(hex);
229
- if (!rgb) {
230
- return null;
231
- }
232
- const [r, g, b] = rgb.map((channel) => {
233
- const c = channel / 255;
234
- return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
235
- });
236
- return 0.2126 * r + 0.7152 * g + 0.0722 * b;
237
- }
238
- /** WCAG contrast ratio between two hex colours, 1–21. Null if either is bad. */
239
- function contrastRatio(foreground, background) {
240
- const l1 = relativeLuminance(foreground);
241
- const l2 = relativeLuminance(background);
242
- if (l1 === null || l2 === null) {
243
- return null;
244
- }
245
- return (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05);
246
- }
247
- /** WCAG 1.4.3 Contrast Minimum, normal-size text. */
248
- const WCAG_AA_NORMAL_TEXT = 4.5;
249
- /**
250
- * The first shade at or below `preferred` on a generated ramp whose contrast
251
- * against `foreground` clears `minRatio`.
252
- *
253
- * This is how the brand colour stays fully tenant-configurable while the
254
- * primary button still passes AA (finding H-03). The shipped default
255
- * `#2AAEC0` gives white text 2.65:1 — the single most important control in the
256
- * product was the least legible one, and any tenant picking a light brand hit
257
- * the same wall. Rather than hardcode a darker teal, which fixes exactly one
258
- * tenant, we keep their hue and step down the ramp their own colour generated
259
- * until the text is readable.
260
- *
261
- * Returns `preferred` unchanged when it already passes, so a tenant whose brand
262
- * is dark enough sees no change at all. Returns the darkest available shade if
263
- * none passes — better to be as close as the palette allows than to give up.
264
- */
265
- function pickAccessibleShade(palette, preferred, foreground = '#ffffff', minRatio = WCAG_AA_NORMAL_TEXT) {
266
- const ladder = ['500', '600', '700', '800', '900'];
267
- const startIndex = ladder.indexOf(preferred);
268
- const candidates = startIndex >= 0 ? ladder.slice(startIndex) : ladder;
269
- let darkestAvailable = null;
270
- for (const step of candidates) {
271
- const shade = palette[step];
272
- if (!shade) {
273
- continue;
274
- }
275
- darkestAvailable = step;
276
- const ratio = contrastRatio(foreground, shade);
277
- if (ratio !== null && ratio >= minRatio) {
278
- return step;
279
- }
280
- }
281
- // Nothing on the ramp clears the threshold — return the darkest step the
282
- // palette actually has rather than one we already know fails. Falls back to
283
- // `preferred` only when the palette carried none of the ladder steps at all.
284
- return darkestAvailable ?? preferred;
285
- }
286
- /** Dark ink used when white text would not be legible on a status colour. */
287
- const READABLE_DARK_INK = '#1f2937';
288
- /**
289
- * Picks the more legible of white and a dark ink for text sitting on `bgColor`.
290
- *
291
- * Status and lookup colours come from a tenant's own catalog, so they can be
292
- * any hex at all — and the count badges on the Explore cards were painting
293
- * white on every one of them, which measured 2.59:1 at the low end (finding
294
- * H-03 / M-04). Rather than restrict what colours a tenant may choose, pick the
295
- * foreground that actually reads on the colour they chose.
296
- *
297
- * Measured with the WCAG relative-luminance ratio, not the perceived-brightness
298
- * shortcut in `getContrastColor`, because that shortcut is not the definition
299
- * conformance is judged against. Unparseable input falls back to white, which
300
- * is the behaviour every caller had before.
301
- */
302
- function readableTextOn(bgColor, dark = READABLE_DARK_INK, light = '#ffffff') {
303
- if (!bgColor) {
304
- return light;
305
- }
306
- const onLight = contrastRatio(light, bgColor);
307
- const onDark = contrastRatio(dark, bgColor);
308
- if (onLight === null || onDark === null) {
309
- return light;
310
- }
311
- return onDark > onLight ? dark : light;
312
- }
313
-
314
164
  /**
315
165
  * Masterteam Design System — raw palettes and scales.
316
166
  *
@@ -964,35 +814,11 @@ function getMTDesignIdentity() {
964
814
  function changePrimaryColor(color) {
965
815
  const isDS = activeDesignIdentity === 'experimental';
966
816
  const base = color || (isDS ? DS_DEFAULT_PRIMARY_COLOR : '#2AAEC0');
967
- const anchor = isDS ? '800' : '500';
968
- const palette = isDS
969
- ? generateTailwindPalette(base, '800')
970
- : generateTailwindPalette(base);
971
- const shade = accessiblePrimaryShade(palette, anchor);
972
817
  updatePreset({
973
818
  semantic: {
974
- primary: palette,
975
- colorScheme: {
976
- light: {
977
- // Re-resolve which step filled controls use, for THIS colour.
978
- //
979
- // The bootstrap preset picks the step from whatever colour the app
980
- // starts with, and a tenant's real brand arrives later — Brand
981
- // Settings pushes it through here. Without recomputing, the step
982
- // stayed the one chosen for the startup colour: the tenant's hue was
983
- // still honoured (the token is a `{primary.N}` reference, so it
984
- // follows the new ramp) but N was decided for a different colour, so
985
- // a light brand could still fail AA and a dark one could render
986
- // needlessly deep. Finding H-03 is only actually closed if this runs
987
- // on the colour the tenant configured.
988
- primary: {
989
- color: `{primary.${shade}}`,
990
- contrastColor: '#ffffff',
991
- hoverColor: `{primary.${shade}}`,
992
- activeColor: `{primary.${shade}}`,
993
- },
994
- },
995
- },
819
+ primary: isDS
820
+ ? generateTailwindPalette(base, '800')
821
+ : generateTailwindPalette(base),
996
822
  },
997
823
  });
998
824
  }
@@ -1028,29 +854,8 @@ function changeTextColor(color) {
1028
854
  },
1029
855
  });
1030
856
  }
1031
- /**
1032
- * The palette step a filled primary control should use so white text on it
1033
- * clears WCAG AA (4.5:1).
1034
- *
1035
- * Kept as a named helper because it is the whole of finding H-03: the shipped
1036
- * default `#2AAEC0` gives white text 2.65:1, so Add / New / Filter / Apply /
1037
- * Submit — the controls that most need to be legible — were the least legible
1038
- * in the product, and every tenant who configured a light brand colour hit the
1039
- * same wall. Darkening the shipped hex would have fixed exactly one tenant and
1040
- * changed the product's colour; this keeps the hue and moves one step down the
1041
- * ramp their own colour already generated. A brand that passes at 500 stays at
1042
- * 500 and looks identical.
1043
- */
1044
- function accessiblePrimaryShade(palette, anchor = '500') {
1045
- return pickAccessibleShade(palette, anchor, '#ffffff', WCAG_AA_NORMAL_TEXT);
1046
- }
1047
857
  const MTPreset = (themeOptions) => {
1048
858
  const textPalette = generateTailwindPalette(themeOptions?.textColor ?? '#334155', '700');
1049
- const primaryPalette = generateTailwindPalette(themeOptions?.primaryColor || '#2AAEC0');
1050
- // Which shade filled controls use. See `accessiblePrimaryShade` — the tenant's
1051
- // hue is untouched; only the step on their own ramp moves, and only when white
1052
- // text would otherwise fail WCAG AA (finding H-03).
1053
- const primaryActionShade = accessiblePrimaryShade(primaryPalette);
1054
859
  const configs = {
1055
860
  options: {
1056
861
  prefix: 'mt',
@@ -1062,16 +867,6 @@ const MTPreset = (themeOptions) => {
1062
867
  semantic: {
1063
868
  colorScheme: {
1064
869
  light: {
1065
- // Filled primary surfaces resolve to the first shade whose contrast
1066
- // with white text passes AA — usually 500, deeper only when the
1067
- // tenant's brand is too light. Borders/icons keep reading `primary.500`
1068
- // directly, so the brand accent itself is unchanged.
1069
- primary: {
1070
- color: `{primary.${primaryActionShade}}`,
1071
- contrastColor: '#ffffff',
1072
- hoverColor: `{primary.${primaryActionShade}}`,
1073
- activeColor: `{primary.${primaryActionShade}}`,
1074
- },
1075
870
  text: {
1076
871
  color: textPalette['700'],
1077
872
  hoverColor: textPalette['800'],
@@ -1088,7 +883,7 @@ const MTPreset = (themeOptions) => {
1088
883
  },
1089
884
  },
1090
885
  },
1091
- primary: primaryPalette,
886
+ primary: generateTailwindPalette(themeOptions?.primaryColor || '#2AAEC0'),
1092
887
  content: {
1093
888
  borderRadius: '{border.radius.lg}',
1094
889
  },
@@ -2380,6 +2175,119 @@ function isInvalid(control) {
2380
2175
  */
2381
2176
  const REQUEST_CONTEXT = new HttpContextToken(() => ({ useBaseUrl: false }));
2382
2177
 
2178
+ /**
2179
+ * Color utility functions for brand display.
2180
+ */
2181
+ /**
2182
+ * Converts a hex color to a light shade (equivalent to primary-100 in Tailwind).
2183
+ * This creates a color with ~10% opacity or a very light tint by mixing with white.
2184
+ */
2185
+ function getLightColor(hexColor) {
2186
+ const hex = hexColor.replace('#', '');
2187
+ const r = parseInt(hex.substring(0, 2), 16);
2188
+ const g = parseInt(hex.substring(2, 4), 16);
2189
+ const b = parseInt(hex.substring(4, 6), 16);
2190
+ const lightR = Math.round(r * 0.1 + 255 * 0.9);
2191
+ const lightG = Math.round(g * 0.1 + 255 * 0.9);
2192
+ const lightB = Math.round(b * 0.1 + 255 * 0.9);
2193
+ return `#${lightR.toString(16).padStart(2, '0')}${lightG
2194
+ .toString(16)
2195
+ .padStart(2, '0')}${lightB.toString(16).padStart(2, '0')}`;
2196
+ }
2197
+ function getContrastColor(bgColor) {
2198
+ let r = 0, g = 0, b = 0;
2199
+ if (bgColor.startsWith('#')) {
2200
+ const hex = bgColor.slice(1);
2201
+ if (hex.length === 3) {
2202
+ r = parseInt(hex[0] + hex[0], 16);
2203
+ g = parseInt(hex[1] + hex[1], 16);
2204
+ b = parseInt(hex[2] + hex[2], 16);
2205
+ }
2206
+ else if (hex.length === 6) {
2207
+ r = parseInt(hex.slice(0, 2), 16);
2208
+ g = parseInt(hex.slice(2, 4), 16);
2209
+ b = parseInt(hex.slice(4, 6), 16);
2210
+ }
2211
+ }
2212
+ const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
2213
+ return luminance > 0.5 ? '' : '#ffffff';
2214
+ }
2215
+ /** Parses `#rgb` / `#rrggbb` into 0-255 channels. Null when unparseable. */
2216
+ function toRgb(hex) {
2217
+ const value = hex.trim().replace('#', '');
2218
+ const full = value.length === 3
2219
+ ? value
2220
+ .split('')
2221
+ .map((c) => c + c)
2222
+ .join('')
2223
+ : value;
2224
+ if (full.length !== 6 || !/^[0-9a-f]{6}$/i.test(full)) {
2225
+ return null;
2226
+ }
2227
+ return [
2228
+ parseInt(full.slice(0, 2), 16),
2229
+ parseInt(full.slice(2, 4), 16),
2230
+ parseInt(full.slice(4, 6), 16),
2231
+ ];
2232
+ }
2233
+ /**
2234
+ * WCAG 2.x relative luminance.
2235
+ *
2236
+ * Note this is NOT the 0.299/0.587/0.114 perceived-brightness formula used by
2237
+ * `getContrastColor` above — that one is fine for "is this light or dark?" but
2238
+ * it is not the definition a conformance ratio is measured against, so it
2239
+ * cannot be used to decide whether text passes AA.
2240
+ */
2241
+ function relativeLuminance(hex) {
2242
+ const rgb = toRgb(hex);
2243
+ if (!rgb) {
2244
+ return null;
2245
+ }
2246
+ const [r, g, b] = rgb.map((channel) => {
2247
+ const c = channel / 255;
2248
+ return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
2249
+ });
2250
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
2251
+ }
2252
+ /** WCAG contrast ratio between two hex colours, 1–21. Null if either is bad. */
2253
+ function contrastRatio(foreground, background) {
2254
+ const l1 = relativeLuminance(foreground);
2255
+ const l2 = relativeLuminance(background);
2256
+ if (l1 === null || l2 === null) {
2257
+ return null;
2258
+ }
2259
+ return (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05);
2260
+ }
2261
+ /** WCAG 1.4.3 Contrast Minimum, normal-size text. */
2262
+ const WCAG_AA_NORMAL_TEXT = 4.5;
2263
+ /** Dark ink used when white text would not be legible on a status colour. */
2264
+ const READABLE_DARK_INK = '#1f2937';
2265
+ /**
2266
+ * Picks the more legible of white and a dark ink for text sitting on `bgColor`.
2267
+ *
2268
+ * Status and lookup colours come from a tenant's own catalog, so they can be
2269
+ * any hex at all — and the count badges on the Explore cards were painting
2270
+ * white on every one of them, which measured 2.59:1 at the low end (finding
2271
+ * H-03 / M-04). Rather than restrict what colours a tenant may choose, pick the
2272
+ * foreground that actually reads on the colour they chose.
2273
+ *
2274
+ * Measured with the WCAG relative-luminance ratio, not the perceived-brightness
2275
+ * shortcut in `getContrastColor`, because that shortcut is not the definition
2276
+ * conformance is judged against. Unparseable input falls back to white, which
2277
+ * is the behaviour every caller had before.
2278
+ */
2279
+ function readableTextOn(bgColor, dark = READABLE_DARK_INK, light = '#ffffff') {
2280
+ if (!bgColor) {
2281
+ return light;
2282
+ }
2283
+ const onLight = contrastRatio(light, bgColor);
2284
+ const onDark = contrastRatio(dark, bgColor);
2285
+ if (onLight === null || onDark === null) {
2286
+ return light;
2287
+ }
2288
+ return onDark > onLight ? dark : light;
2289
+ }
2290
+
2383
2291
  /**
2384
2292
  * A unique DOM id for a form field, shared by its control and its `<label for>`.
2385
2293
  *
@@ -2538,5 +2446,5 @@ function parseDateOnlyValue(value) {
2538
2446
  * Generated bundle index. Do not edit.
2539
2447
  */
2540
2448
 
2541
- export { BaseFacade, BaseFieldConfig, CheckboxFieldConfig, ColorPickerFieldConfig, CrudStateBase, DEFAULT_MT_DATE_FORMATS, DS_BLUE, DS_CHART_SERIES, DS_CONTROL_HEIGHT, DS_DEFAULT_PRIMARY_COLOR, DS_ERROR, DS_FONT_FAMILY, DS_GRAY, DS_INDIGO, DS_RADIUS, DS_SEMANTIC, DS_SHADOW, DS_SUCCESS, DS_WARNING, DateFieldConfig, EditorFieldConfig, EntityListFieldConfig, IconFieldConfig, LocationFieldConfig, LookupMatrixFieldConfig, LookupModuleCheckListFieldConfig, MTDateFormatPipe, MT_DATE_FORMATS, MT_DESIGN_IDENTITY_CLASS, MultiSelectFieldConfig, NumberFieldConfig, PickListFieldConfig, READABLE_DARK_INK, REQUEST_CONTEXT, RadioButtonFieldConfig, RadioCardsFieldConfig, ScheduleItemSelectorFieldConfig, SchedulePredecessorFieldConfig, SchemaConnectionFieldConfig, SelectFieldConfig, SliderFieldConfig, SpacerFieldConfig, TextFieldConfig, TextareaFieldConfig, ToggleFieldConfig, UploadFileFieldConfig, UserSearchFieldConfig, ValidatorConfig, WCAG_AA_NORMAL_TEXT, applyDesignIdentityClass, changeBackgroundColor, changePrimaryColor, changeTextColor, clockTimeToSeconds, contrastRatio, createCustomValidator, createEntityAdapter, dsChartSeries, dsIdentityConfigs, endLoading, formatClockTime, generateTailwindPalette, getContrastColor, getLightColor, getMTDesignIdentity, handleApiRequest, isInvalid, newFieldId, parseClockTime, pickAccessibleShade, provideMTComponents, provideMTConfirmation, provideMTDateFormats, provideMTMessages, readableTextOn, relativeLuminance, setLoadingError, setMTDesignIdentity, startLoading, toAngularDateFormat, toClockTimeParts, wrapValidatorWithMessage };
2449
+ export { BaseFacade, BaseFieldConfig, CheckboxFieldConfig, ColorPickerFieldConfig, CrudStateBase, DEFAULT_MT_DATE_FORMATS, DS_BLUE, DS_CHART_SERIES, DS_CONTROL_HEIGHT, DS_DEFAULT_PRIMARY_COLOR, DS_ERROR, DS_FONT_FAMILY, DS_GRAY, DS_INDIGO, DS_RADIUS, DS_SEMANTIC, DS_SHADOW, DS_SUCCESS, DS_WARNING, DateFieldConfig, EditorFieldConfig, EntityListFieldConfig, IconFieldConfig, LocationFieldConfig, LookupMatrixFieldConfig, LookupModuleCheckListFieldConfig, MTDateFormatPipe, MT_DATE_FORMATS, MT_DESIGN_IDENTITY_CLASS, MultiSelectFieldConfig, NumberFieldConfig, PickListFieldConfig, READABLE_DARK_INK, REQUEST_CONTEXT, RadioButtonFieldConfig, RadioCardsFieldConfig, ScheduleItemSelectorFieldConfig, SchedulePredecessorFieldConfig, SchemaConnectionFieldConfig, SelectFieldConfig, SliderFieldConfig, SpacerFieldConfig, TextFieldConfig, TextareaFieldConfig, ToggleFieldConfig, UploadFileFieldConfig, UserSearchFieldConfig, ValidatorConfig, WCAG_AA_NORMAL_TEXT, applyDesignIdentityClass, changeBackgroundColor, changePrimaryColor, changeTextColor, clockTimeToSeconds, contrastRatio, createCustomValidator, createEntityAdapter, dsChartSeries, dsIdentityConfigs, endLoading, formatClockTime, generateTailwindPalette, getContrastColor, getLightColor, getMTDesignIdentity, handleApiRequest, isInvalid, newFieldId, parseClockTime, provideMTComponents, provideMTConfirmation, provideMTDateFormats, provideMTMessages, readableTextOn, relativeLuminance, setLoadingError, setMTDesignIdentity, startLoading, toAngularDateFormat, toClockTimeParts, wrapValidatorWithMessage };
2542
2450
  //# sourceMappingURL=masterteam-components.mjs.map