@sixbell-telco/sdk 4.2.0 → 4.3.0
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.
- package/CHANGELOG.md +81 -1
- package/README.md +98 -66
- package/_index.css +2 -1586
- package/components/accordion/accordion-item/accordion-item.component.d.ts +1 -1
- package/components/alert/README.md +27 -0
- package/components/alert/index.d.ts +5 -0
- package/components/alert/public-api.d.ts +1 -0
- package/components/alert/src/alert.component.d.ts +85 -0
- package/components/audio-player/audio-timeline/audio-timeline.component.d.ts +1 -1
- package/components/audio-player/button-play/button-play.component.d.ts +7 -7
- package/components/audio-player/src/audio-player.component.d.ts +2 -2
- package/components/audio-player/volume-control/volume-control.component.d.ts +1 -1
- package/components/avatar/README.md +1 -0
- package/components/avatar/src/avatar.component.d.ts +2 -2
- package/components/badge/src/badge.component.d.ts +4 -4
- package/components/button/README.md +5 -4
- package/components/button/src/button.component.d.ts +38 -16
- package/components/card/README.md +2 -0
- package/components/card/card-footer/card-footer.component.d.ts +37 -2
- package/components/card/card-section-group/card-section-group.component.d.ts +1 -1
- package/components/card/src/card.component.d.ts +6 -6
- package/components/countdown/src/countdown.component.d.ts +4 -4
- package/components/data-table/README.md +26 -0
- package/components/data-table/expandable/expandable.component.d.ts +4 -4
- package/components/data-table/sortable-header/sortable-header.component.d.ts +1 -1
- package/components/data-table/src/data-table.component.d.ts +15 -8
- package/components/data-table/sub-component-toggle/sub-component-toggle.component.d.ts +1 -1
- package/components/description-list/README.md +27 -0
- package/components/description-list/index.d.ts +5 -0
- package/components/description-list/public-api.d.ts +1 -0
- package/components/description-list/src/description-list.component.d.ts +90 -0
- package/components/dialog/README.md +10 -6
- package/components/dialog/dialog-actions/dialog-actions.component.d.ts +4 -0
- package/components/dialog/src/dialog.component.d.ts +27 -6
- package/components/dialog/src/fullscreen-block-scroll-strategy.d.ts +31 -0
- package/components/divider/src/divider.component.d.ts +1 -1
- package/components/dropdown/README.md +1 -1
- package/components/dropdown/dropdown-content/dropdown-content.component.d.ts +1 -1
- package/components/dropdown/dropdown-item/dropdown-item.component.d.ts +4 -4
- package/components/dropdown/dropdown-item-checkbox/dropdown-item-checkbox.component.d.ts +5 -5
- package/components/dropdown/dropdown-item-radio/dropdown-item-radio.component.d.ts +5 -5
- package/components/dropdown/dropdown-trigger/dropdown-trigger.component.d.ts +1 -1
- package/components/dropdown-menu/README.md +1 -1
- package/components/dropdown-menu/bar/dropdown-menu-bar/dropdown-menu-bar.component.d.ts +1 -1
- package/components/dropdown-menu/bar/dropdown-menu-bar-content/dropdown-menu-bar-content.component.d.ts +1 -1
- package/components/dropdown-menu/bar/dropdown-menu-bar-item/dropdown-menu-bar-item.component.d.ts +3 -3
- package/components/dropdown-menu/bar/dropdown-menu-bar-item-checkbox/dropdown-menu-bar-item-checkbox.component.d.ts +4 -4
- package/components/dropdown-menu/bar/dropdown-menu-bar-item-radio/dropdown-menu-bar-item-radio.component.d.ts +4 -4
- package/components/dropdown-menu/bar/dropdown-menu-bar-sub-trigger/dropdown-menu-bar-sub-trigger.component.d.ts +1 -1
- package/components/dropdown-menu/bar/dropdown-menu-bar-trigger/dropdown-menu-bar-trigger.component.d.ts +1 -1
- package/components/dropdown-menu/context/dropdown-context-menu-trigger/dropdown-context-menu-trigger.component.d.ts +1 -1
- package/components/dropdown-menu/dropdown-menu-chevron/dropdown-menu-chevron.component.d.ts +1 -1
- package/components/dropdown-menu/src/dropdown-menu-item/dropdown-menu-item.component.d.ts +3 -3
- package/components/dropdown-menu/src/dropdown-menu-sub-trigger/dropdown-menu-sub-trigger.component.d.ts +1 -1
- package/components/empty-state/README.md +40 -0
- package/components/empty-state/index.d.ts +5 -0
- package/components/empty-state/public-api.d.ts +1 -0
- package/components/empty-state/src/empty-state.component.d.ts +73 -0
- package/components/file-upload/file-dropzone/file-dropzone.component.d.ts +4 -4
- package/components/file-upload/file-uploader/file-uploader.component.d.ts +2 -2
- package/components/forms/checkbox/src/checkbox.component.d.ts +1 -1
- package/components/forms/combobox/README.md +1 -0
- package/components/forms/combobox/src/combobox.component.d.ts +21 -7
- package/components/forms/date-picker/src/date-picker.component.d.ts +16 -9
- package/components/forms/form-hint/README.md +29 -0
- package/components/forms/form-hint/index.d.ts +5 -0
- package/components/forms/form-hint/public-api.d.ts +1 -0
- package/components/forms/form-hint/src/form-hint.component.d.ts +38 -0
- package/components/forms/form-item/src/form-item.component.d.ts +45 -1
- package/components/forms/input/src/input.component.d.ts +15 -8
- package/components/forms/radio/src/radio.component.d.ts +1 -1
- package/components/forms/range/src/range.component.d.ts +18 -4
- package/components/forms/select/README.md +1 -0
- package/components/forms/select/src/select.component.d.ts +20 -5
- package/components/forms/switch/src/switch.component.d.ts +1 -1
- package/components/forms/textarea/src/textarea.component.d.ts +12 -5
- package/components/forms/toggle/src/toggle.component.d.ts +1 -1
- package/components/notification/src/notification.component.d.ts +1 -1
- package/components/overlay/README.md +1 -1
- package/components/overlay/overlay-trigger/overlay-trigger.component.d.ts +1 -1
- package/components/overlay/src/overlay.component.d.ts +1 -1
- package/components/paginator/components/pagination-item/pagination-item.component.d.ts +3 -3
- package/components/progress/src/progress.component.d.ts +1 -1
- package/components/segmented-button/README.md +57 -0
- package/components/segmented-button/index.d.ts +5 -0
- package/components/segmented-button/public-api.d.ts +1 -0
- package/components/segmented-button/src/segmented-button.component.d.ts +110 -0
- package/components/sonner/toaster/src/toaster.component.d.ts +3 -3
- package/components/tab/src/tab.component.d.ts +2 -2
- package/components/table/README.md +51 -3
- package/components/table/public-api.d.ts +1 -0
- package/components/table/src/table.component.d.ts +20 -13
- package/components/table/table-action/table-action.component.d.ts +14 -3
- package/components/table/table-actions/table-actions.component.d.ts +12 -1
- package/components/table/tokens/README.md +7 -0
- package/components/table/tokens/index.d.ts +5 -0
- package/components/table/tokens/public-api.d.ts +1 -0
- package/components/table/tokens/table-empty-state.d.ts +6 -0
- package/components/tooltip/README.md +22 -5
- package/components/tooltip/src/tooltip.component.d.ts +36 -4
- package/components/tree/README.md +73 -0
- package/components/tree/index.d.ts +5 -0
- package/components/tree/public-api.d.ts +1 -0
- package/components/tree/src/tree.component.d.ts +180 -0
- package/components/wizard/README.md +9 -0
- package/components/wizard/wizard-content/wizard-content.component.d.ts +1 -1
- package/components/wizard/wizard-wrapper/wizard-wrapper.component.d.ts +15 -6
- package/directives/auto-focus/src/auto-focus.directive.d.ts +1 -1
- package/directives/only-numbers/src/only-numbers.directive.d.ts +1 -1
- package/directives/truncate/README.md +49 -0
- package/directives/truncate/index.d.ts +5 -0
- package/directives/truncate/public-api.d.ts +1 -0
- package/directives/truncate/src/truncate-popover.component.d.ts +11 -0
- package/directives/truncate/src/truncate.directive.d.ts +96 -0
- package/fesm2022/sixbell-telco-sdk-components-accordion.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-accordion.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-alert.mjs +152 -0
- package/fesm2022/sixbell-telco-sdk-components-alert.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-audio-player.mjs +15 -15
- package/fesm2022/sixbell-telco-sdk-components-audio-player.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-avatar.mjs +4 -4
- package/fesm2022/sixbell-telco-sdk-components-avatar.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-badge.mjs +5 -5
- package/fesm2022/sixbell-telco-sdk-components-badge.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-button.mjs +53 -19
- package/fesm2022/sixbell-telco-sdk-components-button.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-card.mjs +61 -14
- package/fesm2022/sixbell-telco-sdk-components-card.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-countdown.mjs +5 -5
- package/fesm2022/sixbell-telco-sdk-components-countdown.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-data-table-sub-component-toggle.mjs +3 -3
- package/fesm2022/sixbell-telco-sdk-components-data-table-sub-component-toggle.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-data-table.mjs +34 -33
- package/fesm2022/sixbell-telco-sdk-components-data-table.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-description-list.mjs +200 -0
- package/fesm2022/sixbell-telco-sdk-components-description-list.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-dialog.mjs +128 -17
- package/fesm2022/sixbell-telco-sdk-components-dialog.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-divider.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-divider.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-bar.mjs +16 -16
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-bar.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-context.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-context.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu.mjs +6 -6
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown.mjs +17 -17
- package/fesm2022/sixbell-telco-sdk-components-dropdown.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dual-list.mjs +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dual-list.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-empty-state.mjs +131 -0
- package/fesm2022/sixbell-telco-sdk-components-empty-state.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-file-upload.mjs +9 -9
- package/fesm2022/sixbell-telco-sdk-components-file-upload.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-checkbox.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-forms-checkbox.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-combobox.mjs +71 -25
- package/fesm2022/sixbell-telco-sdk-components-forms-combobox.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-date-picker.mjs +23 -12
- package/fesm2022/sixbell-telco-sdk-components-forms-date-picker.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-form-hint.mjs +81 -0
- package/fesm2022/sixbell-telco-sdk-components-forms-form-hint.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-forms-form-item.mjs +45 -3
- package/fesm2022/sixbell-telco-sdk-components-forms-form-item.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-input.mjs +27 -13
- package/fesm2022/sixbell-telco-sdk-components-forms-input.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-radio.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-forms-radio.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-range.mjs +29 -7
- package/fesm2022/sixbell-telco-sdk-components-forms-range.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-select.mjs +51 -15
- package/fesm2022/sixbell-telco-sdk-components-forms-select.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-switch.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-forms-switch.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-textarea.mjs +27 -22
- package/fesm2022/sixbell-telco-sdk-components-forms-textarea.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-toggle.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-forms-toggle.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-notification.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-notification.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-overlay.mjs +3 -3
- package/fesm2022/sixbell-telco-sdk-components-overlay.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-paginator.mjs +4 -4
- package/fesm2022/sixbell-telco-sdk-components-paginator.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-progress.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-progress.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-segmented-button.mjs +329 -0
- package/fesm2022/sixbell-telco-sdk-components-segmented-button.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-sonner-toaster.mjs +4 -4
- package/fesm2022/sixbell-telco-sdk-components-sonner-toaster.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-sonner.mjs +4 -4
- package/fesm2022/sixbell-telco-sdk-components-sonner.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-tab.mjs +3 -3
- package/fesm2022/sixbell-telco-sdk-components-tab.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-table-tokens.mjs +14 -0
- package/fesm2022/sixbell-telco-sdk-components-table-tokens.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-table.mjs +63 -32
- package/fesm2022/sixbell-telco-sdk-components-table.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-tooltip.mjs +156 -25
- package/fesm2022/sixbell-telco-sdk-components-tooltip.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-tree.mjs +478 -0
- package/fesm2022/sixbell-telco-sdk-components-tree.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-wizard.mjs +18 -9
- package/fesm2022/sixbell-telco-sdk-components-wizard.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-directives-auto-focus.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-directives-auto-focus.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-directives-only-numbers.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-directives-only-numbers.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-directives-truncate.mjs +339 -0
- package/fesm2022/sixbell-telco-sdk-directives-truncate.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-layouts.mjs +43 -35
- package/fesm2022/sixbell-telco-sdk-layouts.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-date.mjs +15 -2
- package/fesm2022/sixbell-telco-sdk-utils-date.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-mfe.mjs +87 -2
- package/fesm2022/sixbell-telco-sdk-utils-mfe.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-theme.mjs +234 -4
- package/fesm2022/sixbell-telco-sdk-utils-theme.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-translation-testing.mjs +203 -0
- package/fesm2022/sixbell-telco-sdk-utils-translation-testing.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-utils-unsaved-changes.mjs +150 -0
- package/fesm2022/sixbell-telco-sdk-utils-unsaved-changes.mjs.map +1 -0
- package/i18n/sdk/en.json +224 -0
- package/i18n/sdk/es.json +224 -0
- package/i18n/sdk/pt.json +224 -0
- package/layouts/README.md +11 -10
- package/layouts/src/app-layout/app-layout.component.d.ts +11 -8
- package/layouts/src/layout.config.d.ts +1 -1
- package/layouts/src/navbar/navbar.component.d.ts +5 -5
- package/layouts/src/page-banner/page-banner.component.d.ts +6 -1
- package/layouts/src/side-menu/side-menu.component.d.ts +2 -2
- package/layouts/src/user-menu/user-menu.component.d.ts +5 -5
- package/package.json +51 -11
- package/src/_index.css +1616 -0
- package/utils/mfe/README.md +1 -0
- package/utils/mfe/src/hoist-property-rules.d.ts +13 -0
- package/utils/mfe/src/mfe-shadow-shell.component.d.ts +3 -0
- package/utils/theme/README.md +94 -1
- package/utils/theme/public-api.d.ts +2 -1
- package/utils/theme/src/models/theme.d.ts +32 -0
- package/utils/theme/src/overlay/theme-overlay.d.ts +33 -0
- package/utils/theme/src/providers/theme.provider.types.d.ts +7 -0
- package/utils/translation/README.md +61 -0
- package/utils/translation/testing/index.d.ts +5 -0
- package/utils/translation/testing/public-api.d.ts +2 -0
- package/utils/translation/testing/src/translation-testing.d.ts +96 -0
- package/utils/unsaved-changes/README.md +33 -0
- package/utils/unsaved-changes/index.d.ts +5 -0
- package/utils/unsaved-changes/public-api.d.ts +1 -0
- package/utils/unsaved-changes/src/unsaved-changes-dialog.component.d.ts +24 -0
- package/utils/unsaved-changes/src/unsaved-changes.d.ts +50 -0
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
2
3
|
|
|
4
|
+
// Strict custom-format parsing (`dayjs(date, format, true)`) needs this plugin; `extend` is idempotent.
|
|
5
|
+
dayjs.extend(customParseFormat);
|
|
3
6
|
/**
|
|
4
7
|
* Supported display / parsing formats for date utilities.
|
|
5
8
|
* Internally all calculations use ISO `YYYY-MM-DD` and convert to the chosen format for display.
|
|
@@ -26,6 +29,11 @@ const TIME_SECONDS_FORMAT = 'HH:mm:ss';
|
|
|
26
29
|
// 12-hour time format constants
|
|
27
30
|
const TIME_12H_MINUTES_FORMAT = 'h:mm A';
|
|
28
31
|
const TIME_12H_SECONDS_FORMAT = 'h:mm:ss A';
|
|
32
|
+
/** True when `date` has the digit groups and separators of `format` (`MM/DD/YYYY` fits `02/31/2024`). */
|
|
33
|
+
function fitsFormatShape(date, format) {
|
|
34
|
+
const shape = format.replace('YYYY', '9999').replace(/MM|DD/g, '99');
|
|
35
|
+
return date.replace(/\d/g, '9') === shape;
|
|
36
|
+
}
|
|
29
37
|
/**
|
|
30
38
|
* Reusable date utility service for date operations across the SDK.
|
|
31
39
|
* Provides consistent date handling, formatting, and range operations.
|
|
@@ -39,10 +47,15 @@ class DateUtils {
|
|
|
39
47
|
return '';
|
|
40
48
|
// If already ISO, return as-is to avoid misparsing when a display format is provided
|
|
41
49
|
if (/^\d{4}-\d{2}-\d{2}$/.test(date))
|
|
42
|
-
return date;
|
|
50
|
+
return dayjs(date, ISO_DATE_FORMAT, true).format('YYYY-MM-DD');
|
|
43
51
|
if (format && format !== 'YYYY-MM-DD') {
|
|
44
52
|
const parsed = dayjs(date, format, true);
|
|
45
|
-
|
|
53
|
+
if (parsed.isValid())
|
|
54
|
+
return parsed.format('YYYY-MM-DD');
|
|
55
|
+
// Shaped like the format but not a real date (02/31/2024): invalid, never rolled into the next month.
|
|
56
|
+
if (fitsFormatShape(date, format))
|
|
57
|
+
return parsed.format('YYYY-MM-DD');
|
|
58
|
+
return dayjs(date).format('YYYY-MM-DD');
|
|
46
59
|
}
|
|
47
60
|
return dayjs(date).format('YYYY-MM-DD');
|
|
48
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sixbell-telco-sdk-utils-date.mjs","sources":["../../../projects/sdk/utils/date/src/date-utils.ts","../../../projects/sdk/utils/date/sixbell-telco-sdk-utils-date.ts"],"sourcesContent":["import dayjs from 'dayjs';\n\n/**\n * Supported display / parsing formats for date utilities.\n * Internally all calculations use ISO `YYYY-MM-DD` and convert to the chosen format for display.\n */\nexport const SUPPORTED_DATE_FORMATS = [\n\t'DD/MM/YYYY', // Day/Month/Year (European)\n\t'MM/DD/YYYY', // Month/Day/Year (US)\n\t'YYYY-MM-DD', // Year-Month-Day (ISO)\n\t'DD-MM-YYYY', // Day-Month-Year (European with dashes)\n\t'MM-DD-YYYY', // Month-Day-Year (US with dashes)\n\t'YYYY/MM/DD', // Year/Month/Day (ISO with slashes)\n\t'DD.MM.YYYY', // Day.Month.Year (German style)\n\t'MM.DD.YYYY', // Month.Day.Year (US with dots)\n\t'YYYY.MM.DD', // Year.Month.Day (ISO with dots)\n] as const;\n\n/** Union type of all supported format strings. */\nexport type SupportedDateFormat = (typeof SUPPORTED_DATE_FORMATS)[number];\n\n/**\n * Supported time-only formats\n */\nexport const SUPPORTED_TIME_FORMATS = ['HH:mm', 'HH:mm:ss'] as const;\nexport type SupportedTimeFormat = (typeof SUPPORTED_TIME_FORMATS)[number];\n\n// Commonly used format constants\nexport const ISO_DATE_FORMAT: SupportedDateFormat = 'YYYY-MM-DD';\nexport const TIME_MINUTES_FORMAT: SupportedTimeFormat = 'HH:mm';\nexport const TIME_SECONDS_FORMAT: SupportedTimeFormat = 'HH:mm:ss';\n\n// 12-hour time format constants\nexport const TIME_12H_MINUTES_FORMAT = 'h:mm A';\nexport const TIME_12H_SECONDS_FORMAT = 'h:mm:ss A';\n\n// Application-wide default UI date display format\n\n/**\n * Quick action types for range picker\n */\nexport type QuickRangePreset = 'last7Days' | 'last30Days' | 'last6Months' | 'lastYear';\n\n/**\n * Date range representation\n */\nexport interface DateRange {\n\tstart: string;\n\tend: string;\n}\n\n/**\n * Reusable date utility service for date operations across the SDK.\n * Provides consistent date handling, formatting, and range operations.\n */\nexport class DateUtils {\n\t/**\n\t * Convert a date string to ISO format (YYYY-MM-DD)\n\t */\n\tstatic toISODate(date: string, format?: SupportedDateFormat): string {\n\t\tif (!date) return '';\n\t\t// If already ISO, return as-is to avoid misparsing when a display format is provided\n\t\tif (/^\\d{4}-\\d{2}-\\d{2}$/.test(date)) return date;\n\t\tif (format && format !== 'YYYY-MM-DD') {\n\t\t\tconst parsed = dayjs(date, format, true);\n\t\t\treturn parsed.isValid() ? parsed.format('YYYY-MM-DD') : dayjs(date).format('YYYY-MM-DD');\n\t\t}\n\t\treturn dayjs(date).format('YYYY-MM-DD');\n\t}\n\n\t/**\n\t * Convert ISO date to display format\n\t */\n\tstatic toDisplayDate(isoDate: string, format: SupportedDateFormat): string {\n\t\tif (!isoDate) return '';\n\t\treturn dayjs(isoDate).format(format);\n\t}\n\n\t/** Build a combined date-time format string, e.g. `YYYY-MM-DD HH:mm:ss` */\n\tstatic buildDateTimeFormat(dateFmt: SupportedDateFormat, timeFmt: SupportedTimeFormat): string {\n\t\treturn `${dateFmt} ${timeFmt}`;\n\t}\n\n\t/** Infer time format from a time string (returns seconds precision if length is 8) */\n\tstatic inferTimeFormat(time: string | null | undefined): SupportedTimeFormat {\n\t\treturn time?.length === 8 ? TIME_SECONDS_FORMAT : TIME_MINUTES_FORMAT;\n\t}\n\n\t/** Current time formatted per the provided time format */\n\tstatic timeNow(format: SupportedTimeFormat = TIME_SECONDS_FORMAT): string {\n\t\treturn dayjs().format(format);\n\t}\n\n\t/** Milliseconds since epoch for now */\n\tstatic nowMillis(): number {\n\t\treturn dayjs().valueOf();\n\t}\n\n\t/** Convert ISO date + time string into epoch milliseconds using provided time format */\n\tstatic toMillis(isoDate: string, time: string, timeFmt: SupportedTimeFormat): number | null {\n\t\tif (!isoDate || !time) return null;\n\t\tconst fmt = this.buildDateTimeFormat(ISO_DATE_FORMAT, timeFmt);\n\t\tconst dt = dayjs(`${isoDate} ${time}`, fmt);\n\t\treturn dt.isValid() ? dt.valueOf() : null;\n\t}\n\n\t/** Whether a given ISO date equals today (local) */\n\tstatic isTodayISO(isoDate: string): boolean {\n\t\treturn !!isoDate && isoDate === this.today();\n\t}\n\n\t/** End-of-day string for the given time format */\n\tstatic endOfDay(format: SupportedTimeFormat): string {\n\t\treturn format === TIME_SECONDS_FORMAT ? '23:59:59' : '23:59';\n\t}\n\n\t/** Start-of-day string for the given time format */\n\tstatic startOfDay(format: SupportedTimeFormat): string {\n\t\treturn format === TIME_SECONDS_FORMAT ? '00:00:00' : '00:00';\n\t}\n\n\t/** Checks if the provided time string represents end-of-day */\n\tstatic isEndOfDay(time: string | null | undefined): boolean {\n\t\treturn time === '23:59' || time === '23:59:59';\n\t}\n\n\t/**\n\t * Convert 24-hour time format to 12-hour format with AM/PM\n\t * @param time24h Time in HH:mm or HH:mm:ss format\n\t * @param includeSeconds Whether to include seconds in the output\n\t * @returns Time in 12-hour format (h:mm A or h:mm:ss A)\n\t */\n\tstatic to12HourFormat(time24h: string, includeSeconds: boolean = false): string {\n\t\tif (!time24h) return '';\n\n\t\t// Parse the time using dayjs\n\t\tconst timeFormat = includeSeconds ? TIME_SECONDS_FORMAT : TIME_MINUTES_FORMAT;\n\t\tconst timeObj = dayjs(`2000-01-01 ${time24h}`, `YYYY-MM-DD ${timeFormat}`);\n\n\t\tif (!timeObj.isValid()) return time24h;\n\n\t\tconst outputFormat = includeSeconds ? TIME_12H_SECONDS_FORMAT : TIME_12H_MINUTES_FORMAT;\n\t\treturn timeObj.format(outputFormat);\n\t}\n\n\t/**\n\t * Generate range value string for calendar components (ISO/ISO format)\n\t */\n\tstatic toRangeValue(range: DateRange | null): string {\n\t\tif (!range?.start || !range?.end) return '';\n\t\treturn `${range.start}/${range.end}`;\n\t}\n\n\t/**\n\t * Parse range value string from calendar components (ISO/ISO format)\n\t */\n\tstatic parseRangeValue(value: string): DateRange | null {\n\t\tif (!value?.includes('/')) return null;\n\t\tconst [start, end] = value.split('/');\n\t\tif (!start || !end) return null;\n\t\treturn { start, end };\n\t}\n\n\t/**\n\t * Generate quick range based on preset\n\t */\n\tstatic generateQuickRange(preset: QuickRangePreset): DateRange {\n\t\tconst today = dayjs();\n\t\tlet startDate: dayjs.Dayjs;\n\n\t\tswitch (preset) {\n\t\t\tcase 'last7Days':\n\t\t\t\tstartDate = today.subtract(6, 'day'); // inclusive of today => 7 days\n\t\t\t\tbreak;\n\t\t\tcase 'last30Days':\n\t\t\t\tstartDate = today.subtract(29, 'day');\n\t\t\t\tbreak;\n\t\t\tcase 'last6Months':\n\t\t\t\tstartDate = today.subtract(6, 'month');\n\t\t\t\tbreak;\n\t\t\tcase 'lastYear':\n\t\t\t\tstartDate = today.subtract(1, 'year');\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unknown preset: ${preset}`);\n\t\t}\n\n\t\treturn {\n\t\t\tstart: startDate.format('YYYY-MM-DD'),\n\t\t\tend: today.format('YYYY-MM-DD'),\n\t\t};\n\t}\n\n\t/**\n\t * Generate a range representing the last N hours relative to now, including times.\n\t * Returns ISO date range plus HH:mm:ss start/end time strings.\n\t */\n\tstatic generateLastHoursRange(hours: number): { range: DateRange; startTime: string; endTime: string } {\n\t\tconst now = dayjs();\n\t\tconst start = now.subtract(hours, 'hour');\n\t\treturn {\n\t\t\trange: {\n\t\t\t\tstart: start.format('YYYY-MM-DD'),\n\t\t\t\tend: now.format('YYYY-MM-DD'),\n\t\t\t},\n\t\t\tstartTime: start.format('HH:mm:ss'),\n\t\t\tendTime: now.format('HH:mm:ss'),\n\t\t};\n\t}\n\n\t/**\n\t * Validate date range\n\t */\n\tstatic isValidRange(range: DateRange | null): boolean {\n\t\tif (!range?.start || !range?.end) return false;\n\t\treturn dayjs(range.start).isValid() && dayjs(range.end).isValid();\n\t}\n\n\t/**\n\t * Check if a date is valid\n\t */\n\tstatic isValidDate(date: string): boolean {\n\t\treturn dayjs(date).isValid();\n\t}\n\n\t/**\n\t * Get today's date in ISO format\n\t */\n\tstatic today(): string {\n\t\treturn dayjs().format('YYYY-MM-DD');\n\t}\n\n\t/**\n\t * Get yesterday's date in ISO format\n\t */\n\tstatic yesterday(): string {\n\t\treturn dayjs().subtract(1, 'day').format('YYYY-MM-DD');\n\t}\n\n\t/**\n\t * Get tomorrow's date in ISO format\n\t */\n\tstatic tomorrow(): string {\n\t\treturn dayjs().add(1, 'day').format('YYYY-MM-DD');\n\t}\n\n\t/**\n\t * Add/subtract time from a date\n\t */\n\tstatic addTime(date: string, amount: number, unit: dayjs.ManipulateType): string {\n\t\treturn dayjs(date).add(amount, unit).format('YYYY-MM-DD');\n\t}\n\n\t/**\n\t * Get difference between two dates\n\t */\n\tstatic diff(date1: string, date2: string, unit: dayjs.QUnitType = 'day'): number {\n\t\treturn dayjs(date1).diff(dayjs(date2), unit);\n\t}\n\n\t/**\n\t * Check if date is between two dates (inclusive)\n\t */\n\tstatic isBetween(date: string, start: string, end: string): boolean {\n\t\tconst dateObj = dayjs(date);\n\t\tconst startObj = dayjs(start);\n\t\tconst endObj = dayjs(end);\n\t\treturn (dateObj.isAfter(startObj) || dateObj.isSame(startObj)) && (dateObj.isBefore(endObj) || dateObj.isSame(endObj));\n\t}\n\n\t/**\n\t * Format date with custom pattern\n\t */\n\tstatic format(date: string, pattern: string): string {\n\t\treturn dayjs(date).format(pattern);\n\t}\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"m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;AAC3B,QAAA,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC;AAC7B,QAAA,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC;AACzB,QAAA,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACvH;AAEA;;AAEG;AACH,IAAA,OAAO,MAAM,CAAC,IAAY,EAAE,OAAe,EAAA;QAC1C,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;IACnC;AACA;;ACpRD;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"sixbell-telco-sdk-utils-date.mjs","sources":["../../../projects/sdk/utils/date/src/date-utils.ts","../../../projects/sdk/utils/date/sixbell-telco-sdk-utils-date.ts"],"sourcesContent":["import dayjs from 'dayjs';\nimport customParseFormat from 'dayjs/plugin/customParseFormat';\n\n// Strict custom-format parsing (`dayjs(date, format, true)`) needs this plugin; `extend` is idempotent.\ndayjs.extend(customParseFormat);\n\n/**\n * Supported display / parsing formats for date utilities.\n * Internally all calculations use ISO `YYYY-MM-DD` and convert to the chosen format for display.\n */\nexport const SUPPORTED_DATE_FORMATS = [\n\t'DD/MM/YYYY', // Day/Month/Year (European)\n\t'MM/DD/YYYY', // Month/Day/Year (US)\n\t'YYYY-MM-DD', // Year-Month-Day (ISO)\n\t'DD-MM-YYYY', // Day-Month-Year (European with dashes)\n\t'MM-DD-YYYY', // Month-Day-Year (US with dashes)\n\t'YYYY/MM/DD', // Year/Month/Day (ISO with slashes)\n\t'DD.MM.YYYY', // Day.Month.Year (German style)\n\t'MM.DD.YYYY', // Month.Day.Year (US with dots)\n\t'YYYY.MM.DD', // Year.Month.Day (ISO with dots)\n] as const;\n\n/** Union type of all supported format strings. */\nexport type SupportedDateFormat = (typeof SUPPORTED_DATE_FORMATS)[number];\n\n/**\n * Supported time-only formats\n */\nexport const SUPPORTED_TIME_FORMATS = ['HH:mm', 'HH:mm:ss'] as const;\nexport type SupportedTimeFormat = (typeof SUPPORTED_TIME_FORMATS)[number];\n\n// Commonly used format constants\nexport const ISO_DATE_FORMAT: SupportedDateFormat = 'YYYY-MM-DD';\nexport const TIME_MINUTES_FORMAT: SupportedTimeFormat = 'HH:mm';\nexport const TIME_SECONDS_FORMAT: SupportedTimeFormat = 'HH:mm:ss';\n\n// 12-hour time format constants\nexport const TIME_12H_MINUTES_FORMAT = 'h:mm A';\nexport const TIME_12H_SECONDS_FORMAT = 'h:mm:ss A';\n\n// Application-wide default UI date display format\n\n/**\n * Quick action types for range picker\n */\nexport type QuickRangePreset = 'last7Days' | 'last30Days' | 'last6Months' | 'lastYear';\n\n/**\n * Date range representation\n */\nexport interface DateRange {\n\tstart: string;\n\tend: string;\n}\n\n/** True when `date` has the digit groups and separators of `format` (`MM/DD/YYYY` fits `02/31/2024`). */\nfunction fitsFormatShape(date: string, format: SupportedDateFormat): boolean {\n\tconst shape = format.replace('YYYY', '9999').replace(/MM|DD/g, '99');\n\treturn date.replace(/\\d/g, '9') === shape;\n}\n\n/**\n * Reusable date utility service for date operations across the SDK.\n * Provides consistent date handling, formatting, and range operations.\n */\nexport class DateUtils {\n\t/**\n\t * Convert a date string to ISO format (YYYY-MM-DD)\n\t */\n\tstatic toISODate(date: string, format?: SupportedDateFormat): string {\n\t\tif (!date) return '';\n\t\t// If already ISO, return as-is to avoid misparsing when a display format is provided\n\t\tif (/^\\d{4}-\\d{2}-\\d{2}$/.test(date)) return dayjs(date, ISO_DATE_FORMAT, true).format('YYYY-MM-DD');\n\t\tif (format && format !== 'YYYY-MM-DD') {\n\t\t\tconst parsed = dayjs(date, format, true);\n\t\t\tif (parsed.isValid()) return parsed.format('YYYY-MM-DD');\n\t\t\t// Shaped like the format but not a real date (02/31/2024): invalid, never rolled into the next month.\n\t\t\tif (fitsFormatShape(date, format)) return parsed.format('YYYY-MM-DD');\n\t\t\treturn dayjs(date).format('YYYY-MM-DD');\n\t\t}\n\t\treturn dayjs(date).format('YYYY-MM-DD');\n\t}\n\n\t/**\n\t * Convert ISO date to display format\n\t */\n\tstatic toDisplayDate(isoDate: string, format: SupportedDateFormat): string {\n\t\tif (!isoDate) return '';\n\t\treturn dayjs(isoDate).format(format);\n\t}\n\n\t/** Build a combined date-time format string, e.g. `YYYY-MM-DD HH:mm:ss` */\n\tstatic buildDateTimeFormat(dateFmt: SupportedDateFormat, timeFmt: SupportedTimeFormat): string {\n\t\treturn `${dateFmt} ${timeFmt}`;\n\t}\n\n\t/** Infer time format from a time string (returns seconds precision if length is 8) */\n\tstatic inferTimeFormat(time: string | null | undefined): SupportedTimeFormat {\n\t\treturn time?.length === 8 ? TIME_SECONDS_FORMAT : TIME_MINUTES_FORMAT;\n\t}\n\n\t/** Current time formatted per the provided time format */\n\tstatic timeNow(format: SupportedTimeFormat = TIME_SECONDS_FORMAT): string {\n\t\treturn dayjs().format(format);\n\t}\n\n\t/** Milliseconds since epoch for now */\n\tstatic nowMillis(): number {\n\t\treturn dayjs().valueOf();\n\t}\n\n\t/** Convert ISO date + time string into epoch milliseconds using provided time format */\n\tstatic toMillis(isoDate: string, time: string, timeFmt: SupportedTimeFormat): number | null {\n\t\tif (!isoDate || !time) return null;\n\t\tconst fmt = this.buildDateTimeFormat(ISO_DATE_FORMAT, timeFmt);\n\t\tconst dt = dayjs(`${isoDate} ${time}`, fmt);\n\t\treturn dt.isValid() ? dt.valueOf() : null;\n\t}\n\n\t/** Whether a given ISO date equals today (local) */\n\tstatic isTodayISO(isoDate: string): boolean {\n\t\treturn !!isoDate && isoDate === this.today();\n\t}\n\n\t/** End-of-day string for the given time format */\n\tstatic endOfDay(format: SupportedTimeFormat): string {\n\t\treturn format === TIME_SECONDS_FORMAT ? '23:59:59' : '23:59';\n\t}\n\n\t/** Start-of-day string for the given time format */\n\tstatic startOfDay(format: SupportedTimeFormat): string {\n\t\treturn format === TIME_SECONDS_FORMAT ? '00:00:00' : '00:00';\n\t}\n\n\t/** Checks if the provided time string represents end-of-day */\n\tstatic isEndOfDay(time: string | null | undefined): boolean {\n\t\treturn time === '23:59' || time === '23:59:59';\n\t}\n\n\t/**\n\t * Convert 24-hour time format to 12-hour format with AM/PM\n\t * @param time24h Time in HH:mm or HH:mm:ss format\n\t * @param includeSeconds Whether to include seconds in the output\n\t * @returns Time in 12-hour format (h:mm A or h:mm:ss A)\n\t */\n\tstatic to12HourFormat(time24h: string, includeSeconds: boolean = false): string {\n\t\tif (!time24h) return '';\n\n\t\t// Parse the time using dayjs\n\t\tconst timeFormat = includeSeconds ? TIME_SECONDS_FORMAT : TIME_MINUTES_FORMAT;\n\t\tconst timeObj = dayjs(`2000-01-01 ${time24h}`, `YYYY-MM-DD ${timeFormat}`);\n\n\t\tif (!timeObj.isValid()) return time24h;\n\n\t\tconst outputFormat = includeSeconds ? TIME_12H_SECONDS_FORMAT : TIME_12H_MINUTES_FORMAT;\n\t\treturn timeObj.format(outputFormat);\n\t}\n\n\t/**\n\t * Generate range value string for calendar components (ISO/ISO format)\n\t */\n\tstatic toRangeValue(range: DateRange | null): string {\n\t\tif (!range?.start || !range?.end) return '';\n\t\treturn `${range.start}/${range.end}`;\n\t}\n\n\t/**\n\t * Parse range value string from calendar components (ISO/ISO format)\n\t */\n\tstatic parseRangeValue(value: string): DateRange | null {\n\t\tif (!value?.includes('/')) return null;\n\t\tconst [start, end] = value.split('/');\n\t\tif (!start || !end) return null;\n\t\treturn { start, end };\n\t}\n\n\t/**\n\t * Generate quick range based on preset\n\t */\n\tstatic generateQuickRange(preset: QuickRangePreset): DateRange {\n\t\tconst today = dayjs();\n\t\tlet startDate: dayjs.Dayjs;\n\n\t\tswitch (preset) {\n\t\t\tcase 'last7Days':\n\t\t\t\tstartDate = today.subtract(6, 'day'); // inclusive of today => 7 days\n\t\t\t\tbreak;\n\t\t\tcase 'last30Days':\n\t\t\t\tstartDate = today.subtract(29, 'day');\n\t\t\t\tbreak;\n\t\t\tcase 'last6Months':\n\t\t\t\tstartDate = today.subtract(6, 'month');\n\t\t\t\tbreak;\n\t\t\tcase 'lastYear':\n\t\t\t\tstartDate = today.subtract(1, 'year');\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unknown preset: ${preset}`);\n\t\t}\n\n\t\treturn {\n\t\t\tstart: startDate.format('YYYY-MM-DD'),\n\t\t\tend: today.format('YYYY-MM-DD'),\n\t\t};\n\t}\n\n\t/**\n\t * Generate a range representing the last N hours relative to now, including times.\n\t * Returns ISO date range plus HH:mm:ss start/end time strings.\n\t */\n\tstatic generateLastHoursRange(hours: number): { range: DateRange; startTime: string; endTime: string } {\n\t\tconst now = dayjs();\n\t\tconst start = now.subtract(hours, 'hour');\n\t\treturn {\n\t\t\trange: {\n\t\t\t\tstart: start.format('YYYY-MM-DD'),\n\t\t\t\tend: now.format('YYYY-MM-DD'),\n\t\t\t},\n\t\t\tstartTime: start.format('HH:mm:ss'),\n\t\t\tendTime: now.format('HH:mm:ss'),\n\t\t};\n\t}\n\n\t/**\n\t * Validate date range\n\t */\n\tstatic isValidRange(range: DateRange | null): boolean {\n\t\tif (!range?.start || !range?.end) return false;\n\t\treturn dayjs(range.start).isValid() && dayjs(range.end).isValid();\n\t}\n\n\t/**\n\t * Check if a date is valid\n\t */\n\tstatic isValidDate(date: string): boolean {\n\t\treturn dayjs(date).isValid();\n\t}\n\n\t/**\n\t * Get today's date in ISO format\n\t */\n\tstatic today(): string {\n\t\treturn dayjs().format('YYYY-MM-DD');\n\t}\n\n\t/**\n\t * Get yesterday's date in ISO format\n\t */\n\tstatic yesterday(): string {\n\t\treturn dayjs().subtract(1, 'day').format('YYYY-MM-DD');\n\t}\n\n\t/**\n\t * Get tomorrow's date in ISO format\n\t */\n\tstatic tomorrow(): string {\n\t\treturn dayjs().add(1, 'day').format('YYYY-MM-DD');\n\t}\n\n\t/**\n\t * Add/subtract time from a date\n\t */\n\tstatic addTime(date: string, amount: number, unit: dayjs.ManipulateType): string {\n\t\treturn dayjs(date).add(amount, unit).format('YYYY-MM-DD');\n\t}\n\n\t/**\n\t * Get difference between two dates\n\t */\n\tstatic diff(date1: string, date2: string, unit: dayjs.QUnitType = 'day'): number {\n\t\treturn dayjs(date1).diff(dayjs(date2), unit);\n\t}\n\n\t/**\n\t * Check if date is between two dates (inclusive)\n\t */\n\tstatic isBetween(date: string, start: string, end: string): boolean {\n\t\tconst dateObj = dayjs(date);\n\t\tconst startObj = dayjs(start);\n\t\tconst endObj = dayjs(end);\n\t\treturn (dateObj.isAfter(startObj) || dateObj.isSame(startObj)) && (dateObj.isBefore(endObj) || dateObj.isSame(endObj));\n\t}\n\n\t/**\n\t * Format date with custom pattern\n\t */\n\tstatic format(date: string, pattern: string): string {\n\t\treturn dayjs(date).format(pattern);\n\t}\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;AAGA;AACA,KAAK,CAAC,MAAM,CAAC,iBAAiB,CAAC;AAE/B;;;AAGG;AACI,MAAM,sBAAsB,GAAG;AACrC,IAAA,YAAY;AACZ,IAAA,YAAY;AACZ,IAAA,YAAY;AACZ,IAAA,YAAY;AACZ,IAAA,YAAY;AACZ,IAAA,YAAY;AACZ,IAAA,YAAY;AACZ,IAAA,YAAY;AACZ,IAAA,YAAY;;AAMb;;AAEG;MACU,sBAAsB,GAAG,CAAC,OAAO,EAAE,UAAU;AAG1D;AACO,MAAM,eAAe,GAAwB;AAC7C,MAAM,mBAAmB,GAAwB;AACjD,MAAM,mBAAmB,GAAwB;AAExD;AACO,MAAM,uBAAuB,GAAG;AAChC,MAAM,uBAAuB,GAAG;AAiBvC;AACA,SAAS,eAAe,CAAC,IAAY,EAAE,MAA2B,EAAA;AACjE,IAAA,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,OAAO,C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AAG,CAAC;AACzB,QAAA,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACvH;AAEA;;AAEG;AACH,IAAA,OAAO,MAAM,CAAC,IAAY,EAAE,OAAe,EAAA;QAC1C,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;IACnC;AACA;;ACjSD;;AAEG;;;;"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken, signal, Injectable, inject, ElementRef, DestroyRef, computed, afterNextRender, ChangeDetectionStrategy, ViewEncapsulation, Component } from '@angular/core';
|
|
2
|
+
import { InjectionToken, signal, Injectable, inject, ElementRef, DestroyRef, computed, afterNextRender, isDevMode, ChangeDetectionStrategy, ViewEncapsulation, Component } from '@angular/core';
|
|
3
3
|
import { DOCUMENT } from '@angular/common';
|
|
4
4
|
import { RouterOutlet } from '@angular/router';
|
|
5
|
+
import { LoggerService } from '@sixbell-telco/sdk/utils/logger';
|
|
5
6
|
import { Dialog } from '@angular/cdk/dialog';
|
|
6
7
|
import { OverlayContainer, Overlay } from '@angular/cdk/overlay';
|
|
7
8
|
|
|
@@ -16,6 +17,79 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
|
|
|
16
17
|
type: Injectable
|
|
17
18
|
}] });
|
|
18
19
|
|
|
20
|
+
const PROPERTIES_ATTRIBUTE = 'data-st-mfe-properties';
|
|
21
|
+
const PROPERTY_NAME = /^@property\s+(--[^\s{]+)/;
|
|
22
|
+
function collectPropertyRules(rules, into) {
|
|
23
|
+
for (const rule of Array.from(rules)) {
|
|
24
|
+
if (rule.cssText.startsWith('@property'))
|
|
25
|
+
into.push(rule.cssText);
|
|
26
|
+
else if ('cssRules' in rule)
|
|
27
|
+
collectPropertyRules(rule.cssRules, into);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function propertyName(rule) {
|
|
31
|
+
return PROPERTY_NAME.exec(rule)?.[1] ?? null;
|
|
32
|
+
}
|
|
33
|
+
/** Names of the custom properties the document already registers with `@property`, readable sheets only. */
|
|
34
|
+
function documentPropertyNames(document) {
|
|
35
|
+
const names = new Set();
|
|
36
|
+
for (const sheet of Array.from(document.styleSheets)) {
|
|
37
|
+
const rules = [];
|
|
38
|
+
try {
|
|
39
|
+
collectPropertyRules(sheet.cssRules, rules);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
rules.forEach((rule) => names.add(propertyName(rule) ?? ''));
|
|
45
|
+
}
|
|
46
|
+
for (const style of Array.from(document.head?.querySelectorAll(`style[${PROPERTIES_ATTRIBUTE}]`) ?? [])) {
|
|
47
|
+
for (const match of (style.textContent ?? '').matchAll(/@property\s+(--[^\s{]+)/g))
|
|
48
|
+
names.add(match[1]);
|
|
49
|
+
}
|
|
50
|
+
names.delete('');
|
|
51
|
+
return names;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Registers a child stylesheet's `@property` rules at document level, once per `source`.
|
|
55
|
+
*
|
|
56
|
+
* Browsers ignore `@property` inside a shadow root, and Tailwind v4 relies on it for the initial values of
|
|
57
|
+
* `--tw-*` variables (`border`, `shadow-*`, `ring-*`, `translate-*`, gradients...). Registration is global
|
|
58
|
+
* and the first one wins, so properties the document already registers are skipped: a child built with a
|
|
59
|
+
* different Tailwind version never changes the host's initial values.
|
|
60
|
+
*
|
|
61
|
+
* Returns `'unreadable'` when the sheet's rules cannot be read (a cross-origin sheet served without CORS).
|
|
62
|
+
*/
|
|
63
|
+
function hoistMfePropertyRules(sheet, source, document) {
|
|
64
|
+
if (!document.head || !sheet)
|
|
65
|
+
return 'nothing-to-hoist';
|
|
66
|
+
const hoisted = Array.from(document.head.querySelectorAll(`style[${PROPERTIES_ATTRIBUTE}]`));
|
|
67
|
+
if (hoisted.some((style) => style.getAttribute(PROPERTIES_ATTRIBUTE) === source))
|
|
68
|
+
return 'already-hoisted';
|
|
69
|
+
const rules = [];
|
|
70
|
+
try {
|
|
71
|
+
collectPropertyRules(sheet.cssRules, rules);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return 'unreadable';
|
|
75
|
+
}
|
|
76
|
+
const registered = documentPropertyNames(document);
|
|
77
|
+
const missing = rules.filter((rule) => {
|
|
78
|
+
const name = propertyName(rule);
|
|
79
|
+
if (!name || registered.has(name))
|
|
80
|
+
return false;
|
|
81
|
+
registered.add(name);
|
|
82
|
+
return true;
|
|
83
|
+
});
|
|
84
|
+
if (!missing.length)
|
|
85
|
+
return 'nothing-to-hoist';
|
|
86
|
+
const style = document.createElement('style');
|
|
87
|
+
style.setAttribute(PROPERTIES_ATTRIBUTE, source);
|
|
88
|
+
style.textContent = missing.join('\n');
|
|
89
|
+
document.head.append(style);
|
|
90
|
+
return 'hoisted';
|
|
91
|
+
}
|
|
92
|
+
|
|
19
93
|
/**
|
|
20
94
|
* CDK overlay container that renders inside the federated child's shadow root, so the child's
|
|
21
95
|
* compiled stylesheet styles its dialogs, menus and popovers. Without a registered shell (the
|
|
@@ -101,6 +175,7 @@ const STYLES_ATTRIBUTE = 'data-st-mfe-styles';
|
|
|
101
175
|
* Route component that mounts a federated child inside its own shadow root: it attaches the child's
|
|
102
176
|
* compiled stylesheet there, hides the content until it loads (no unstyled flash), and registers the
|
|
103
177
|
* shadow root so CDK overlays opened by the child render inside it. Theme tokens inherit from the host.
|
|
178
|
+
* Its Tailwind `@property` registrations the document lacks are hoisted to it, where browsers honour them.
|
|
104
179
|
* Configure it with `provideMfeShadowShell` on the same route.
|
|
105
180
|
*/
|
|
106
181
|
class MfeShadowShellComponent {
|
|
@@ -109,6 +184,7 @@ class MfeShadowShellComponent {
|
|
|
109
184
|
document = inject(DOCUMENT);
|
|
110
185
|
host = inject(ElementRef).nativeElement;
|
|
111
186
|
destroyRef = inject(DestroyRef);
|
|
187
|
+
logger = inject(LoggerService);
|
|
112
188
|
stylesReady = signal(false);
|
|
113
189
|
visibility = computed(() => (this.stylesReady() ? 'visible' : 'hidden'));
|
|
114
190
|
constructor() {
|
|
@@ -127,13 +203,22 @@ class MfeShadowShellComponent {
|
|
|
127
203
|
link.rel = 'stylesheet';
|
|
128
204
|
link.setAttribute(STYLES_ATTRIBUTE, '');
|
|
129
205
|
const reveal = () => this.stylesReady.set(true);
|
|
130
|
-
link.addEventListener('load',
|
|
206
|
+
link.addEventListener('load', () => {
|
|
207
|
+
this.hoistPropertyRules(link);
|
|
208
|
+
reveal();
|
|
209
|
+
}, { once: true });
|
|
131
210
|
link.addEventListener('error', reveal, { once: true });
|
|
132
211
|
const timer = setTimeout(reveal, this.config.revealTimeoutMs ?? 1500);
|
|
133
212
|
this.destroyRef.onDestroy(() => clearTimeout(timer));
|
|
134
213
|
link.href = await mfeStylesheetHref(this.config);
|
|
135
214
|
shadowRoot.prepend(link);
|
|
136
215
|
}
|
|
216
|
+
hoistPropertyRules(link) {
|
|
217
|
+
const href = link.getAttribute('href') ?? '';
|
|
218
|
+
if (hoistMfePropertyRules(link.sheet, href, this.document) !== 'unreadable' || !isDevMode())
|
|
219
|
+
return;
|
|
220
|
+
this.logger.warn(`MFE shadow shell: cannot read the rules of ${href} (cross-origin without CORS?), so its @property rules were not hoisted and Tailwind border, shadow, ring and translate utilities may not resolve. Serve it with CORS or from the host origin.`, { component: 'MfeShadowShellComponent', href });
|
|
221
|
+
}
|
|
137
222
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: MfeShadowShellComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
138
223
|
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.25", type: MfeShadowShellComponent, isStandalone: true, selector: "st-mfe-shadow-shell", ngImport: i0, template: '<div [style.visibility]="visibility()"><router-outlet /></div>', isInline: true, styles: [":host{display:block}\n"], dependencies: [{ kind: "directive", type: RouterOutlet, selector: "router-outlet", inputs: ["name", "routerOutletData"], outputs: ["activate", "deactivate", "attach", "detach"], exportAs: ["outlet"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.ShadowDom });
|
|
139
224
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sixbell-telco-sdk-utils-mfe.mjs","sources":["../../../projects/sdk/utils/mfe/src/mfe-shadow-root.ts","../../../projects/sdk/utils/mfe/src/shadow-root-overlay-container.ts","../../../projects/sdk/utils/mfe/src/provide-mfe-shadow-shell.ts","../../../projects/sdk/utils/mfe/src/mfe-shadow-shell.component.ts","../../../projects/sdk/utils/mfe/sixbell-telco-sdk-utils-mfe.ts"],"sourcesContent":["import { Injectable, InjectionToken, signal } from '@angular/core';\n\n/** Where a federated child MFE serves its compiled stylesheet. */\nexport interface MfeShadowShellConfig {\n\t/** Public path the host mounts the child under, with a trailing slash (e.g. `/mfe-aux-tables/`). */\n\tbasePath: string;\n\t/**\n\t * Module (relative to `basePath`) whose export holds the hashed stylesheet href written after the build.\n\t * Defaults to `assets/stylesheet-href.js`.\n\t */\n\tstylesheetHrefModule?: string;\n\t/** Export name read from `stylesheetHrefModule`. Defaults to `stylesheetHref`. */\n\tstylesheetHrefExport?: string;\n\t/** Reveal the content after this delay even if the stylesheet never answers. Defaults to 1500 ms. */\n\trevealTimeoutMs?: number;\n}\n\nexport const MFE_SHADOW_SHELL_CONFIG = new InjectionToken<MfeShadowShellConfig>('MFE_SHADOW_SHELL_CONFIG');\n\n/** Route-scoped registry of the shell's shadow root, so overlays opened by the child render inside it. */\n@Injectable()\nexport class MfeShadowRoot {\n\treadonly root = signal<ShadowRoot | null>(null);\n}\n","import { OverlayContainer } from '@angular/cdk/overlay';\nimport { Injectable, inject } from '@angular/core';\nimport { MfeShadowRoot } from './mfe-shadow-root';\n\n/**\n * CDK overlay container that renders inside the federated child's shadow root, so the child's\n * compiled stylesheet styles its dialogs, menus and popovers. Without a registered shell (the\n * standalone dev harness) it stays on the document body, where the styles are global.\n */\n@Injectable()\nexport class ShadowRootOverlayContainer extends OverlayContainer {\n\tprivate readonly shell = inject(MfeShadowRoot, { optional: true });\n\n\toverride getContainerElement(): HTMLElement {\n\t\tconst container = super.getContainerElement();\n\t\tconst shadowRoot = this.shell?.root();\n\t\tif (shadowRoot && container.parentNode !== shadowRoot) {\n\t\t\tshadowRoot.appendChild(container);\n\t\t}\n\t\treturn container;\n\t}\n}\n","import { Dialog } from '@angular/cdk/dialog';\nimport { Overlay, OverlayContainer } from '@angular/cdk/overlay';\nimport { Provider } from '@angular/core';\nimport { MFE_SHADOW_SHELL_CONFIG, MfeShadowRoot, MfeShadowShellConfig } from './mfe-shadow-root';\nimport { ShadowRootOverlayContainer } from './shadow-root-overlay-container';\n\ntype StylesheetModuleImporter = (url: string) => Promise<Record<string, unknown>>;\n\nconst importModule: StylesheetModuleImporter = (url) => import(/* @vite-ignore */ /* webpackIgnore: true */ url);\nconst hrefCache = new Map<string, Promise<string>>();\nconst PRELOAD_ATTRIBUTE = 'data-st-mfe-styles-preload';\n\n/**\n * Resolves the child's compiled stylesheet href: the hashed name written after the build, read from\n * `stylesheetHrefModule`, or `<basePath>styles.css` when that module is missing.\n */\nexport async function resolveMfeStylesheetHref(config: MfeShadowShellConfig, importer: StylesheetModuleImporter = importModule): Promise<string> {\n\tconst fallback = `${config.basePath}styles.css`;\n\ttry {\n\t\tconst module = await importer(`${config.basePath}${config.stylesheetHrefModule ?? 'assets/stylesheet-href.js'}?v=${Date.now()}`);\n\t\tconst href = module[config.stylesheetHrefExport ?? 'stylesheetHref'];\n\t\treturn typeof href === 'string' && href ? href : fallback;\n\t} catch {\n\t\treturn fallback;\n\t}\n}\n\n/** One resolution per child per page load; also preloads the stylesheet in the document head. */\nexport function mfeStylesheetHref(config: MfeShadowShellConfig): Promise<string> {\n\tlet href = hrefCache.get(config.basePath);\n\tif (!href) {\n\t\thref = resolveMfeStylesheetHref(config);\n\t\threfCache.set(config.basePath, href);\n\t\tvoid href.then(preloadStylesheet);\n\t}\n\treturn href;\n}\n\nfunction preloadStylesheet(href: string): void {\n\tconst head = globalThis.document?.head;\n\tif (!head || head.querySelector(`link[${PRELOAD_ATTRIBUTE}][href=\"${href}\"]`)) return;\n\tconst preload = globalThis.document.createElement('link');\n\tpreload.rel = 'preload';\n\tpreload.as = 'style';\n\tpreload.href = href;\n\tpreload.setAttribute(PRELOAD_ATTRIBUTE, '');\n\thead.append(preload);\n}\n\n/**\n * Route providers for a federated child mounted through `MfeShadowShellComponent`: the shell config,\n * the shadow-root registry, and CDK Overlay/Dialog scoped to the route so overlays open inside it.\n *\n * ```ts\n * { path: '', component: MfeShadowShellComponent, providers: provideMfeShadowShell({ basePath: '/mfe-aux-tables/' }), children }\n * ```\n */\nexport function provideMfeShadowShell(config: MfeShadowShellConfig): Provider[] {\n\tvoid mfeStylesheetHref(config);\n\treturn [\n\t\t{ provide: MFE_SHADOW_SHELL_CONFIG, useValue: config },\n\t\tMfeShadowRoot,\n\t\t{ provide: OverlayContainer, useClass: ShadowRootOverlayContainer },\n\t\t{ provide: Overlay, useClass: Overlay },\n\t\t{ provide: Dialog, useClass: Dialog },\n\t];\n}\n","import { DOCUMENT } from '@angular/common';\nimport {\n\tChangeDetectionStrategy,\n\tComponent,\n\tDestroyRef,\n\tElementRef,\n\tViewEncapsulation,\n\tafterNextRender,\n\tcomputed,\n\tinject,\n\tsignal,\n} from '@angular/core';\nimport { RouterOutlet } from '@angular/router';\nimport { MFE_SHADOW_SHELL_CONFIG, MfeShadowRoot } from './mfe-shadow-root';\nimport { mfeStylesheetHref } from './provide-mfe-shadow-shell';\n\nconst STYLES_ATTRIBUTE = 'data-st-mfe-styles';\n\n/**\n * Route component that mounts a federated child inside its own shadow root: it attaches the child's\n * compiled stylesheet there, hides the content until it loads (no unstyled flash), and registers the\n * shadow root so CDK overlays opened by the child render inside it. Theme tokens inherit from the host.\n * Configure it with `provideMfeShadowShell` on the same route.\n */\n@Component({\n\tselector: 'st-mfe-shadow-shell',\n\timports: [RouterOutlet],\n\ttemplate: '<div [style.visibility]=\"visibility()\"><router-outlet /></div>',\n\tstyles: ':host { display: block; }',\n\tencapsulation: ViewEncapsulation.ShadowDom,\n\tchangeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class MfeShadowShellComponent {\n\tprivate readonly config = inject(MFE_SHADOW_SHELL_CONFIG);\n\tprivate readonly registry = inject(MfeShadowRoot);\n\tprivate readonly document = inject(DOCUMENT);\n\tprivate readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n\tprivate readonly destroyRef = inject(DestroyRef);\n\tprivate readonly stylesReady = signal(false);\n\n\tprotected readonly visibility = computed(() => (this.stylesReady() ? 'visible' : 'hidden'));\n\n\tconstructor() {\n\t\tconst shadowRoot = this.host.shadowRoot;\n\t\tif (shadowRoot) this.registry.root.set(shadowRoot);\n\t\tthis.destroyRef.onDestroy(() => this.registry.root.set(null));\n\t\tafterNextRender(() => void this.attachStylesheet(shadowRoot));\n\t}\n\n\tprivate async attachStylesheet(shadowRoot: ShadowRoot | null): Promise<void> {\n\t\tif (!shadowRoot || shadowRoot.querySelector(`link[${STYLES_ATTRIBUTE}]`)) {\n\t\t\tthis.stylesReady.set(true);\n\t\t\treturn;\n\t\t}\n\t\tconst link = this.document.createElement('link');\n\t\tlink.rel = 'stylesheet';\n\t\tlink.setAttribute(STYLES_ATTRIBUTE, '');\n\t\tconst reveal = () => this.stylesReady.set(true);\n\t\tlink.addEventListener('load', reveal, { once: true });\n\t\tlink.addEventListener('error', reveal, { once: true });\n\t\tconst timer = setTimeout(reveal, this.config.revealTimeoutMs ?? 1500);\n\t\tthis.destroyRef.onDestroy(() => clearTimeout(timer));\n\t\tlink.href = await mfeStylesheetHref(this.config);\n\t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,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;4FAAvB,uBAAuB,EAAA,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,qBAAA,EAAA,QAAA,EAAA,EAAA,EAAA,QAAA,EALzB,gEAAgE,EAAA,QAAA,EAAA,IAAA,EAAA,MAAA,EAAA,CAAA,wBAAA,CAAA,EAAA,YAAA,EAAA,CAAA,EAAA,IAAA,EAAA,WAAA,EAAA,IAAA,EADhE,YAAY,EAAA,QAAA,EAAA,eAAA,EAAA,MAAA,EAAA,CAAA,MAAA,EAAA,kBAAA,CAAA,EAAA,OAAA,EAAA,CAAA,UAAA,EAAA,YAAA,EAAA,QAAA,EAAA,QAAA,CAAA,EAAA,QAAA,EAAA,CAAA,QAAA,CAAA,EAAA,CAAA,EAAA,eAAA,EAAA,EAAA,CAAA,uBAAA,CAAA,MAAA,EAAA,aAAA,EAAA,EAAA,CAAA,iBAAA,CAAA,SAAA,EAAA,CAAA;;4FAMV,uBAAuB,EAAA,UAAA,EAAA,CAAA;kBARnC,SAAS;AACC,YAAA,IAAA,EAAA,CAAA,EAAA,QAAA,EAAA,qBAAqB,EAAA,OAAA,EACtB,CAAC,YAAY,CAAC,EAAA,QAAA,EACb,gEAAgE,EAAA,aAAA,EAE3D,iBAAiB,CAAC,SAAS,EAAA,eAAA,EACzB,uBAAuB,CAAC,MAAM,EAAA,MAAA,EAAA,CAAA,wBAAA,CAAA,EAAA;;;AC9BhD;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"sixbell-telco-sdk-utils-mfe.mjs","sources":["../../../projects/sdk/utils/mfe/src/mfe-shadow-root.ts","../../../projects/sdk/utils/mfe/src/hoist-property-rules.ts","../../../projects/sdk/utils/mfe/src/shadow-root-overlay-container.ts","../../../projects/sdk/utils/mfe/src/provide-mfe-shadow-shell.ts","../../../projects/sdk/utils/mfe/src/mfe-shadow-shell.component.ts","../../../projects/sdk/utils/mfe/sixbell-telco-sdk-utils-mfe.ts"],"sourcesContent":["import { Injectable, InjectionToken, signal } from '@angular/core';\n\n/** Where a federated child MFE serves its compiled stylesheet. */\nexport interface MfeShadowShellConfig {\n\t/** Public path the host mounts the child under, with a trailing slash (e.g. `/mfe-aux-tables/`). */\n\tbasePath: string;\n\t/**\n\t * Module (relative to `basePath`) whose export holds the hashed stylesheet href written after the build.\n\t * Defaults to `assets/stylesheet-href.js`.\n\t */\n\tstylesheetHrefModule?: string;\n\t/** Export name read from `stylesheetHrefModule`. Defaults to `stylesheetHref`. */\n\tstylesheetHrefExport?: string;\n\t/** Reveal the content after this delay even if the stylesheet never answers. Defaults to 1500 ms. */\n\trevealTimeoutMs?: number;\n}\n\nexport const MFE_SHADOW_SHELL_CONFIG = new InjectionToken<MfeShadowShellConfig>('MFE_SHADOW_SHELL_CONFIG');\n\n/** Route-scoped registry of the shell's shadow root, so overlays opened by the child render inside it. */\n@Injectable()\nexport class MfeShadowRoot {\n\treadonly root = signal<ShadowRoot | null>(null);\n}\n","const PROPERTIES_ATTRIBUTE = 'data-st-mfe-properties';\nconst PROPERTY_NAME = /^@property\\s+(--[^\\s{]+)/;\n\n/** Outcome of {@link hoistMfePropertyRules}. */\nexport type MfePropertyHoistResult = 'hoisted' | 'nothing-to-hoist' | 'already-hoisted' | 'unreadable';\n\nfunction collectPropertyRules(rules: CSSRuleList, into: string[]): void {\n\tfor (const rule of Array.from(rules)) {\n\t\tif (rule.cssText.startsWith('@property')) into.push(rule.cssText);\n\t\telse if ('cssRules' in rule) collectPropertyRules((rule as CSSGroupingRule).cssRules, into);\n\t}\n}\n\nfunction propertyName(rule: string): string | null {\n\treturn PROPERTY_NAME.exec(rule)?.[1] ?? null;\n}\n\n/** Names of the custom properties the document already registers with `@property`, readable sheets only. */\nfunction documentPropertyNames(document: Document): Set<string> {\n\tconst names = new Set<string>();\n\tfor (const sheet of Array.from(document.styleSheets)) {\n\t\tconst rules: string[] = [];\n\t\ttry {\n\t\t\tcollectPropertyRules(sheet.cssRules, rules);\n\t\t} catch {\n\t\t\tcontinue;\n\t\t}\n\t\trules.forEach((rule) => names.add(propertyName(rule) ?? ''));\n\t}\n\tfor (const style of Array.from(document.head?.querySelectorAll(`style[${PROPERTIES_ATTRIBUTE}]`) ?? [])) {\n\t\tfor (const match of (style.textContent ?? '').matchAll(/@property\\s+(--[^\\s{]+)/g)) names.add(match[1]);\n\t}\n\tnames.delete('');\n\treturn names;\n}\n\n/**\n * Registers a child stylesheet's `@property` rules at document level, once per `source`.\n *\n * Browsers ignore `@property` inside a shadow root, and Tailwind v4 relies on it for the initial values of\n * `--tw-*` variables (`border`, `shadow-*`, `ring-*`, `translate-*`, gradients...). Registration is global\n * and the first one wins, so properties the document already registers are skipped: a child built with a\n * different Tailwind version never changes the host's initial values.\n *\n * Returns `'unreadable'` when the sheet's rules cannot be read (a cross-origin sheet served without CORS).\n */\nexport function hoistMfePropertyRules(sheet: CSSStyleSheet | null, source: string, document: Document): MfePropertyHoistResult {\n\tif (!document.head || !sheet) return 'nothing-to-hoist';\n\tconst hoisted = Array.from(document.head.querySelectorAll(`style[${PROPERTIES_ATTRIBUTE}]`));\n\tif (hoisted.some((style) => style.getAttribute(PROPERTIES_ATTRIBUTE) === source)) return 'already-hoisted';\n\tconst rules: string[] = [];\n\ttry {\n\t\tcollectPropertyRules(sheet.cssRules, rules);\n\t} catch {\n\t\treturn 'unreadable';\n\t}\n\tconst registered = documentPropertyNames(document);\n\tconst missing = rules.filter((rule) => {\n\t\tconst name = propertyName(rule);\n\t\tif (!name || registered.has(name)) return false;\n\t\tregistered.add(name);\n\t\treturn true;\n\t});\n\tif (!missing.length) return 'nothing-to-hoist';\n\tconst style = document.createElement('style');\n\tstyle.setAttribute(PROPERTIES_ATTRIBUTE, source);\n\tstyle.textContent = missing.join('\\n');\n\tdocument.head.append(style);\n\treturn 'hoisted';\n}\n","import { OverlayContainer } from '@angular/cdk/overlay';\nimport { Injectable, inject } from '@angular/core';\nimport { MfeShadowRoot } from './mfe-shadow-root';\n\n/**\n * CDK overlay container that renders inside the federated child's shadow root, so the child's\n * compiled stylesheet styles its dialogs, menus and popovers. Without a registered shell (the\n * standalone dev harness) it stays on the document body, where the styles are global.\n */\n@Injectable()\nexport class ShadowRootOverlayContainer extends OverlayContainer {\n\tprivate readonly shell = inject(MfeShadowRoot, { optional: true });\n\n\toverride getContainerElement(): HTMLElement {\n\t\tconst container = super.getContainerElement();\n\t\tconst shadowRoot = this.shell?.root();\n\t\tif (shadowRoot && container.parentNode !== shadowRoot) {\n\t\t\tshadowRoot.appendChild(container);\n\t\t}\n\t\treturn container;\n\t}\n}\n","import { Dialog } from '@angular/cdk/dialog';\nimport { Overlay, OverlayContainer } from '@angular/cdk/overlay';\nimport { Provider } from '@angular/core';\nimport { MFE_SHADOW_SHELL_CONFIG, MfeShadowRoot, MfeShadowShellConfig } from './mfe-shadow-root';\nimport { ShadowRootOverlayContainer } from './shadow-root-overlay-container';\n\ntype StylesheetModuleImporter = (url: string) => Promise<Record<string, unknown>>;\n\nconst importModule: StylesheetModuleImporter = (url) => import(/* @vite-ignore */ /* webpackIgnore: true */ url);\nconst hrefCache = new Map<string, Promise<string>>();\nconst PRELOAD_ATTRIBUTE = 'data-st-mfe-styles-preload';\n\n/**\n * Resolves the child's compiled stylesheet href: the hashed name written after the build, read from\n * `stylesheetHrefModule`, or `<basePath>styles.css` when that module is missing.\n */\nexport async function resolveMfeStylesheetHref(config: MfeShadowShellConfig, importer: StylesheetModuleImporter = importModule): Promise<string> {\n\tconst fallback = `${config.basePath}styles.css`;\n\ttry {\n\t\tconst module = await importer(`${config.basePath}${config.stylesheetHrefModule ?? 'assets/stylesheet-href.js'}?v=${Date.now()}`);\n\t\tconst href = module[config.stylesheetHrefExport ?? 'stylesheetHref'];\n\t\treturn typeof href === 'string' && href ? href : fallback;\n\t} catch {\n\t\treturn fallback;\n\t}\n}\n\n/** One resolution per child per page load; also preloads the stylesheet in the document head. */\nexport function mfeStylesheetHref(config: MfeShadowShellConfig): Promise<string> {\n\tlet href = hrefCache.get(config.basePath);\n\tif (!href) {\n\t\thref = resolveMfeStylesheetHref(config);\n\t\threfCache.set(config.basePath, href);\n\t\tvoid href.then(preloadStylesheet);\n\t}\n\treturn href;\n}\n\nfunction preloadStylesheet(href: string): void {\n\tconst head = globalThis.document?.head;\n\tif (!head || head.querySelector(`link[${PRELOAD_ATTRIBUTE}][href=\"${href}\"]`)) return;\n\tconst preload = globalThis.document.createElement('link');\n\tpreload.rel = 'preload';\n\tpreload.as = 'style';\n\tpreload.href = href;\n\tpreload.setAttribute(PRELOAD_ATTRIBUTE, '');\n\thead.append(preload);\n}\n\n/**\n * Route providers for a federated child mounted through `MfeShadowShellComponent`: the shell config,\n * the shadow-root registry, and CDK Overlay/Dialog scoped to the route so overlays open inside it.\n *\n * ```ts\n * { path: '', component: MfeShadowShellComponent, providers: provideMfeShadowShell({ basePath: '/mfe-aux-tables/' }), children }\n * ```\n */\nexport function provideMfeShadowShell(config: MfeShadowShellConfig): Provider[] {\n\tvoid mfeStylesheetHref(config);\n\treturn [\n\t\t{ provide: MFE_SHADOW_SHELL_CONFIG, useValue: config },\n\t\tMfeShadowRoot,\n\t\t{ provide: OverlayContainer, useClass: ShadowRootOverlayContainer },\n\t\t{ provide: Overlay, useClass: Overlay },\n\t\t{ provide: Dialog, useClass: Dialog },\n\t];\n}\n","import { DOCUMENT } from '@angular/common';\nimport {\n\tChangeDetectionStrategy,\n\tComponent,\n\tDestroyRef,\n\tElementRef,\n\tViewEncapsulation,\n\tafterNextRender,\n\tcomputed,\n\tinject,\n\tisDevMode,\n\tsignal,\n} from '@angular/core';\nimport { RouterOutlet } from '@angular/router';\nimport { LoggerService } from '@sixbell-telco/sdk/utils/logger';\nimport { hoistMfePropertyRules } from './hoist-property-rules';\nimport { MFE_SHADOW_SHELL_CONFIG, MfeShadowRoot } from './mfe-shadow-root';\nimport { mfeStylesheetHref } from './provide-mfe-shadow-shell';\n\nconst STYLES_ATTRIBUTE = 'data-st-mfe-styles';\n\n/**\n * Route component that mounts a federated child inside its own shadow root: it attaches the child's\n * compiled stylesheet there, hides the content until it loads (no unstyled flash), and registers the\n * shadow root so CDK overlays opened by the child render inside it. Theme tokens inherit from the host.\n * Its Tailwind `@property` registrations the document lacks are hoisted to it, where browsers honour them.\n * Configure it with `provideMfeShadowShell` on the same route.\n */\n@Component({\n\tselector: 'st-mfe-shadow-shell',\n\timports: [RouterOutlet],\n\ttemplate: '<div [style.visibility]=\"visibility()\"><router-outlet /></div>',\n\tstyles: ':host { display: block; }',\n\tencapsulation: ViewEncapsulation.ShadowDom,\n\tchangeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class MfeShadowShellComponent {\n\tprivate readonly config = inject(MFE_SHADOW_SHELL_CONFIG);\n\tprivate readonly registry = inject(MfeShadowRoot);\n\tprivate readonly document = inject(DOCUMENT);\n\tprivate readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n\tprivate readonly destroyRef = inject(DestroyRef);\n\tprivate readonly logger = inject(LoggerService);\n\tprivate readonly stylesReady = signal(false);\n\n\tprotected readonly visibility = computed(() => (this.stylesReady() ? 'visible' : 'hidden'));\n\n\tconstructor() {\n\t\tconst shadowRoot = this.host.shadowRoot;\n\t\tif (shadowRoot) this.registry.root.set(shadowRoot);\n\t\tthis.destroyRef.onDestroy(() => this.registry.root.set(null));\n\t\tafterNextRender(() => void this.attachStylesheet(shadowRoot));\n\t}\n\n\tprivate async attachStylesheet(shadowRoot: ShadowRoot | null): Promise<void> {\n\t\tif (!shadowRoot || shadowRoot.querySelector(`link[${STYLES_ATTRIBUTE}]`)) {\n\t\t\tthis.stylesReady.set(true);\n\t\t\treturn;\n\t\t}\n\t\tconst link = this.document.createElement('link');\n\t\tlink.rel = 'stylesheet';\n\t\tlink.setAttribute(STYLES_ATTRIBUTE, '');\n\t\tconst reveal = () => this.stylesReady.set(true);\n\t\tlink.addEventListener(\n\t\t\t'load',\n\t\t\t() => {\n\t\t\t\tthis.hoistPropertyRules(link);\n\t\t\t\treveal();\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tlink.addEventListener('error', reveal, { once: true });\n\t\tconst timer = setTimeout(reveal, this.config.revealTimeoutMs ?? 1500);\n\t\tthis.destroyRef.onDestroy(() => clearTimeout(timer));\n\t\tlink.href = await mfeStylesheetHref(this.config);\n\t\tshadowRoot.prepend(link);\n\t}\n\n\tprivate hoistPropertyRules(link: HTMLLinkElement): void {\n\t\tconst href = link.getAttribute('href') ?? '';\n\t\tif (hoistMfePropertyRules(link.sheet, href, this.document) !== 'unreadable' || !isDevMode()) return;\n\t\tthis.logger.warn(\n\t\t\t`MFE shadow shell: cannot read the rules of ${href} (cross-origin without CORS?), so its @property rules were not hoisted and Tailwind border, shadow, ring and translate utilities may not resolve. Serve it with CORS or from the host origin.`,\n\t\t\t{ component: 'MfeShadowShellComponent', href },\n\t\t);\n\t}\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;MAiBa,uBAAuB,GAAG,IAAI,cAAc,CAAuB,yBAAyB;AAEzG;MAEa,aAAa,CAAA;AAChB,IAAA,IAAI,GAAG,MAAM,CAAoB,IAAI,CAAC;wGADnC,aAAa,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;4GAAb,aAAa,EAAA,CAAA;;4FAAb,aAAa,EAAA,UAAA,EAAA,CAAA;kBADzB;;;ACpBD,MAAM,oBAAoB,GAAG,wBAAwB;AACrD,MAAM,aAAa,GAAG,0BAA0B;AAKhD,SAAS,oBAAoB,CAAC,KAAkB,EAAE,IAAc,EAAA;IAC/D,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;AACrC,QAAA,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC;AAAE,YAAA,IAAI,CAAC,IAAI,CAAC,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,MAAM,CAAC,IAAI,CACf,8CAA8C,IAAI,CAAA,6LAAA,CAA+L,EACjP,EAAE,SAAS,EAAE,yBAAyB,EAAE,IAAI,EAAE,CAC9C;IACF;wGAjDY,uBAAuB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;4FAAvB,uBAAuB,EAAA,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,qBAAA,EAAA,QAAA,EAAA,EAAA,EAAA,QAAA,EALzB,gEAAgE,EAAA,QAAA,EAAA,IAAA,EAAA,MAAA,EAAA,CAAA,wBAAA,CAAA,EAAA,YAAA,EAAA,CAAA,EAAA,IAAA,EAAA,WAAA,EAAA,IAAA,EADhE,YAAY,EAAA,QAAA,EAAA,eAAA,EAAA,MAAA,EAAA,CAAA,MAAA,EAAA,kBAAA,CAAA,EAAA,OAAA,EAAA,CAAA,UAAA,EAAA,YAAA,EAAA,QAAA,EAAA,QAAA,CAAA,EAAA,QAAA,EAAA,CAAA,QAAA,CAAA,EAAA,CAAA,EAAA,eAAA,EAAA,EAAA,CAAA,uBAAA,CAAA,MAAA,EAAA,aAAA,EAAA,EAAA,CAAA,iBAAA,CAAA,SAAA,EAAA,CAAA;;4FAMV,uBAAuB,EAAA,UAAA,EAAA,CAAA;kBARnC,SAAS;AACC,YAAA,IAAA,EAAA,CAAA,EAAA,QAAA,EAAA,qBAAqB,EAAA,OAAA,EACtB,CAAC,YAAY,CAAC,EAAA,QAAA,EACb,gEAAgE,EAAA,aAAA,EAE3D,iBAAiB,CAAC,SAAS,EAAA,eAAA,EACzB,uBAAuB,CAAC,MAAM,EAAA,MAAA,EAAA,CAAA,wBAAA,CAAA,EAAA;;;AClChD;;AAEG;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { inject, Injectable, signal, RendererFactory2, computed, makeEnvironmentProviders, provideAppInitializer, InjectionToken, effect, provideEnvironmentInitializer } from '@angular/core';
|
|
3
3
|
import { LoggerService } from '@sixbell-telco/sdk/utils/logger';
|
|
4
|
-
import {
|
|
4
|
+
import { RuntimeConfigLoader, RuntimeConfigStore, RuntimeUpdateAdapter } from '@sixbell-telco/sdk/utils/runtime-config';
|
|
5
5
|
import { TranslationService } from '@sixbell-telco/sdk/utils/translation';
|
|
6
6
|
import { DOCUMENT } from '@angular/common';
|
|
7
7
|
|
|
@@ -284,6 +284,195 @@ const DARK_THEME_CLASS = 'dark';
|
|
|
284
284
|
*/
|
|
285
285
|
const DARK_MODE_MEDIA_QUERY = '(prefers-color-scheme: dark)';
|
|
286
286
|
|
|
287
|
+
const SCHEMES = ['light', 'dark'];
|
|
288
|
+
const CATEGORIES = ['colors', 'radius', 'sizes', 'effects', 'others'];
|
|
289
|
+
const OVERLAY_KEYS = new Set(['meta', 'target', 'themes']);
|
|
290
|
+
const TOKEN_NAME = /^--[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
291
|
+
const UNSAFE_VALUE = /[;{}<>]|\/\*/;
|
|
292
|
+
const THEME_OVERLAY_SCHEMA_VERSION = '3';
|
|
293
|
+
/** DaisyUI core tokens. Overlays can never set them; product looks come from the shared catalog. */
|
|
294
|
+
const THEME_OVERLAY_CORE_TOKENS = [
|
|
295
|
+
'--color-base-100',
|
|
296
|
+
'--color-base-200',
|
|
297
|
+
'--color-base-300',
|
|
298
|
+
'--color-base-content',
|
|
299
|
+
...['primary', 'secondary', 'accent', 'neutral', 'info', 'success', 'warning', 'error'].flatMap((name) => [
|
|
300
|
+
`--color-${name}`,
|
|
301
|
+
`--color-${name}-content`,
|
|
302
|
+
]),
|
|
303
|
+
'--radius-selector',
|
|
304
|
+
'--radius-field',
|
|
305
|
+
'--radius-box',
|
|
306
|
+
'--size-selector',
|
|
307
|
+
'--size-field',
|
|
308
|
+
'--border',
|
|
309
|
+
'--depth',
|
|
310
|
+
'--noise',
|
|
311
|
+
];
|
|
312
|
+
/** Prefixes of catalog tokens a product overlay may override. Any other catalog token is owned by the catalog. */
|
|
313
|
+
const THEME_OVERLAY_OVERRIDABLE_PREFIXES = ['--color-counters-', '--color-metrics-'];
|
|
314
|
+
function isRecord$1(value) {
|
|
315
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
316
|
+
}
|
|
317
|
+
function overlayName(value) {
|
|
318
|
+
const meta = isRecord$1(value) ? value['meta'] : undefined;
|
|
319
|
+
return isRecord$1(meta) && typeof meta['name'] === 'string' ? meta['name'] : 'overlay';
|
|
320
|
+
}
|
|
321
|
+
function checkMeta(meta, errors) {
|
|
322
|
+
if (!isRecord$1(meta)) {
|
|
323
|
+
errors.push('meta must be an object');
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
for (const field of ['name', 'hash', 'updatedAt']) {
|
|
327
|
+
const value = meta[field];
|
|
328
|
+
if (typeof value !== 'string' || value.trim() === '')
|
|
329
|
+
errors.push(`meta.${field} must be a non-empty string`);
|
|
330
|
+
}
|
|
331
|
+
if (meta['schemaVersion'] !== THEME_OVERLAY_SCHEMA_VERSION)
|
|
332
|
+
errors.push(`meta.schemaVersion must be "${THEME_OVERLAY_SCHEMA_VERSION}"`);
|
|
333
|
+
}
|
|
334
|
+
function checkToken(path, token, value, errors) {
|
|
335
|
+
if (!TOKEN_NAME.test(token))
|
|
336
|
+
errors.push(`${path} ${token} is not a lowercase custom property name`);
|
|
337
|
+
if (THEME_OVERLAY_CORE_TOKENS.includes(token))
|
|
338
|
+
errors.push(`${path} ${token} is a DaisyUI core token and cannot be overlaid`);
|
|
339
|
+
if (typeof value !== 'string' || value.trim() === '')
|
|
340
|
+
errors.push(`${path} ${token} must be a non-empty string`);
|
|
341
|
+
else if (UNSAFE_VALUE.test(value))
|
|
342
|
+
errors.push(`${path} ${token} has a value that is not a single CSS value`);
|
|
343
|
+
}
|
|
344
|
+
/** Returns the tokens one scheme declares, recording structural errors. */
|
|
345
|
+
function collectSchemeTokens(themes, scheme, errors) {
|
|
346
|
+
const tokens = new Set();
|
|
347
|
+
const variant = themes[scheme];
|
|
348
|
+
const variables = isRecord$1(variant) ? variant['variables'] : undefined;
|
|
349
|
+
if (!isRecord$1(variables)) {
|
|
350
|
+
errors.push(`themes.${scheme}.variables must be an object`);
|
|
351
|
+
return tokens;
|
|
352
|
+
}
|
|
353
|
+
for (const [category, entries] of Object.entries(variables)) {
|
|
354
|
+
const path = `themes.${scheme}.variables.${category}`;
|
|
355
|
+
if (!CATEGORIES.includes(category)) {
|
|
356
|
+
errors.push(`${path} is not one of ${CATEGORIES.join(', ')}`);
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
if (!isRecord$1(entries)) {
|
|
360
|
+
errors.push(`${path} must be an object`);
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
for (const [token, value] of Object.entries(entries)) {
|
|
364
|
+
checkToken(path, token, value, errors);
|
|
365
|
+
if (tokens.has(token))
|
|
366
|
+
errors.push(`themes.${scheme} declares ${token} in more than one category`);
|
|
367
|
+
tokens.add(token);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return tokens;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Validates an overlay file on its own: shape, schema version, token names and values, no DaisyUI core tokens,
|
|
374
|
+
* and the same tokens in `light` and `dark`. Returns the errors; an empty array means valid.
|
|
375
|
+
*/
|
|
376
|
+
function validateThemeOverlay(value) {
|
|
377
|
+
if (!isRecord$1(value))
|
|
378
|
+
return ['overlay must be a JSON object'];
|
|
379
|
+
const errors = Object.keys(value)
|
|
380
|
+
.filter((key) => !OVERLAY_KEYS.has(key))
|
|
381
|
+
.map((key) => `unexpected key ${key}`);
|
|
382
|
+
checkMeta(value['meta'], errors);
|
|
383
|
+
const target = value['target'];
|
|
384
|
+
if (target !== undefined && (typeof target !== 'string' || target.trim() === ''))
|
|
385
|
+
errors.push('target must be a theme name');
|
|
386
|
+
checkThemes(value['themes'], errors);
|
|
387
|
+
return errors;
|
|
388
|
+
}
|
|
389
|
+
/** Checks the `themes` block: only `light` and `dark`, valid tokens, and the same tokens in both. */
|
|
390
|
+
function checkThemes(themes, errors) {
|
|
391
|
+
if (!isRecord$1(themes)) {
|
|
392
|
+
errors.push('themes must be an object with light and dark');
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
for (const key of Object.keys(themes)) {
|
|
396
|
+
if (!SCHEMES.includes(key))
|
|
397
|
+
errors.push(`themes.${key} is not light or dark`);
|
|
398
|
+
}
|
|
399
|
+
const [light, dark] = SCHEMES.map((scheme) => collectSchemeTokens(themes, scheme, errors));
|
|
400
|
+
const unpaired = (from, to, fromScheme, toScheme) => [...from].filter((token) => !to.has(token)).map((token) => `${token} is set for ${fromScheme} but not for ${toScheme}`);
|
|
401
|
+
errors.push(...unpaired(light, dark, 'light', 'dark'), ...unpaired(dark, light, 'dark', 'light'));
|
|
402
|
+
if (light.size === 0 && dark.size === 0 && errors.length === 0)
|
|
403
|
+
errors.push('overlay declares no tokens');
|
|
404
|
+
}
|
|
405
|
+
function catalogTokens(theme, scheme) {
|
|
406
|
+
const variables = theme.themes[scheme].variables;
|
|
407
|
+
return new Set(CATEGORIES.flatMap((category) => Object.keys(variables[category] ?? {})));
|
|
408
|
+
}
|
|
409
|
+
function overlayEntries(overlay, scheme) {
|
|
410
|
+
const variables = overlay.themes[scheme].variables;
|
|
411
|
+
return CATEGORIES.flatMap((category) => Object.entries(variables[category] ?? {}).map(([token, value]) => [category, token, value]));
|
|
412
|
+
}
|
|
413
|
+
/** True when the overlay applies to `themeName`: it names that theme, or names none. */
|
|
414
|
+
function themeOverlayAppliesTo(overlay, themeName) {
|
|
415
|
+
return overlay.target === undefined || overlay.target === themeName;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Validates an overlay against the catalog it extends: it may add tokens the catalog lacks and override catalog
|
|
419
|
+
* tokens whose names start with one of `THEME_OVERLAY_OVERRIDABLE_PREFIXES`.
|
|
420
|
+
*/
|
|
421
|
+
function validateThemeOverlayFor(overlay, theme) {
|
|
422
|
+
const errors = validateThemeOverlay(overlay);
|
|
423
|
+
if (errors.length)
|
|
424
|
+
return errors;
|
|
425
|
+
const valid = overlay;
|
|
426
|
+
for (const scheme of SCHEMES) {
|
|
427
|
+
const existing = catalogTokens(theme, scheme);
|
|
428
|
+
for (const [, token] of overlayEntries(valid, scheme)) {
|
|
429
|
+
if (existing.has(token) && !THEME_OVERLAY_OVERRIDABLE_PREFIXES.some((prefix) => token.startsWith(prefix))) {
|
|
430
|
+
errors.push(`themes.${scheme} ${token} is defined by the ${theme.meta.name} catalog and is not overridable`);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return errors;
|
|
435
|
+
}
|
|
436
|
+
/** Returns a copy of `theme` with the overlay's tokens set for both schemes. Validate first. */
|
|
437
|
+
function mergeThemeOverlay(theme, overlay) {
|
|
438
|
+
const mergeScheme = (scheme) => {
|
|
439
|
+
const base = theme.themes[scheme];
|
|
440
|
+
const variables = Object.fromEntries(CATEGORIES.map((category) => [category, { ...base.variables[category] }]));
|
|
441
|
+
for (const [category, token, value] of overlayEntries(overlay, scheme)) {
|
|
442
|
+
for (const other of CATEGORIES)
|
|
443
|
+
delete variables[other][token];
|
|
444
|
+
variables[category][token] = value;
|
|
445
|
+
}
|
|
446
|
+
return { ...base, variables };
|
|
447
|
+
};
|
|
448
|
+
return { ...theme, themes: { light: mergeScheme('light'), dark: mergeScheme('dark') } };
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Layers every overlay that targets `theme` on top of it, in order. An overlay with any error is skipped whole,
|
|
452
|
+
* so a scheme never gets half an overlay; its errors are returned for logging.
|
|
453
|
+
*/
|
|
454
|
+
function applyThemeOverlays(theme, overlays) {
|
|
455
|
+
let config = theme;
|
|
456
|
+
const errors = [];
|
|
457
|
+
for (const overlay of overlays) {
|
|
458
|
+
const structural = validateThemeOverlay(overlay);
|
|
459
|
+
if (structural.length) {
|
|
460
|
+
errors.push(...structural.map((error) => `${overlayName(overlay)}: ${error}`));
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
const valid = overlay;
|
|
464
|
+
if (!themeOverlayAppliesTo(valid, theme.meta.name))
|
|
465
|
+
continue;
|
|
466
|
+
const conflicts = validateThemeOverlayFor(valid, theme);
|
|
467
|
+
if (conflicts.length) {
|
|
468
|
+
errors.push(...conflicts.map((error) => `${valid.meta.name}: ${error}`));
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
config = mergeThemeOverlay(config, valid);
|
|
472
|
+
}
|
|
473
|
+
return { config, errors };
|
|
474
|
+
}
|
|
475
|
+
|
|
287
476
|
/**
|
|
288
477
|
* Theme Utility Functions
|
|
289
478
|
* Pure, side-effect-free utilities for theme logic
|
|
@@ -1762,6 +1951,29 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
|
|
|
1762
1951
|
args: [{ providedIn: 'root' }]
|
|
1763
1952
|
}], ctorParameters: () => [] });
|
|
1764
1953
|
|
|
1954
|
+
/** Loads one overlay file through the runtime cache; returns `undefined` when it cannot be fetched. */
|
|
1955
|
+
async function loadThemeOverlay(overlayPath, { store, logger, appId, forceRefresh }) {
|
|
1956
|
+
const loader = new RuntimeConfigLoader(overlayPath, {
|
|
1957
|
+
fallbackData: null,
|
|
1958
|
+
schemaVersion: THEME_SCHEMA_VERSION,
|
|
1959
|
+
resource: 'theme',
|
|
1960
|
+
store,
|
|
1961
|
+
logger,
|
|
1962
|
+
appId,
|
|
1963
|
+
});
|
|
1964
|
+
let result = forceRefresh ? await loader.refresh() : await loader.loadLatest();
|
|
1965
|
+
if (result.source === 'cache') {
|
|
1966
|
+
const check = await loader.checkForUpdates(result.hash).catch(() => undefined);
|
|
1967
|
+
if (check?.updated) {
|
|
1968
|
+
result = await loader.refresh();
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
if (result.source === 'fallback') {
|
|
1972
|
+
logger.warn('Theme overlay not loaded', { component: 'ThemeProvider', action: 'loadOverlay', path: overlayPath });
|
|
1973
|
+
return undefined;
|
|
1974
|
+
}
|
|
1975
|
+
return result.data;
|
|
1976
|
+
}
|
|
1765
1977
|
function provideRuntimeTheme(configPath, options) {
|
|
1766
1978
|
return makeEnvironmentProviders([
|
|
1767
1979
|
provideAppInitializer(() => {
|
|
@@ -1770,6 +1982,8 @@ function provideRuntimeTheme(configPath, options) {
|
|
|
1770
1982
|
const logger = inject(LoggerService);
|
|
1771
1983
|
const configStore = new RuntimeConfigStore('theme-runtime-config', options?.appId);
|
|
1772
1984
|
const themeStore = new RuntimeConfigStore('theme-runtime-config', options?.appId);
|
|
1985
|
+
const overlayStore = new RuntimeConfigStore('theme-runtime-config', options?.appId);
|
|
1986
|
+
let overlays = [];
|
|
1773
1987
|
const configLoader = new RuntimeConfigLoader(configPath, {
|
|
1774
1988
|
fallbackData: {
|
|
1775
1989
|
meta: {
|
|
@@ -1854,14 +2068,28 @@ function provideRuntimeTheme(configPath, options) {
|
|
|
1854
2068
|
}
|
|
1855
2069
|
return result.data;
|
|
1856
2070
|
};
|
|
2071
|
+
const loadOverlays = async (paths, forceRefresh = false) => {
|
|
2072
|
+
const overlayPaths = [...(paths ?? []), ...(options?.overlays ?? [])];
|
|
2073
|
+
const loaded = await Promise.all(overlayPaths.map((overlayPath) => loadThemeOverlay(overlayPath, { store: overlayStore, logger, appId: options?.appId, forceRefresh })));
|
|
2074
|
+
return loaded.filter((overlay) => overlay !== undefined);
|
|
2075
|
+
};
|
|
1857
2076
|
const applyThemeConfig = async (config, blocking) => {
|
|
1858
2077
|
const themeName = config.meta?.name;
|
|
1859
2078
|
if (!themeName) {
|
|
1860
2079
|
throw new Error('Theme meta.name missing for config apply');
|
|
1861
2080
|
}
|
|
2081
|
+
const layered = applyThemeOverlays(config, overlays);
|
|
2082
|
+
if (layered.errors.length) {
|
|
2083
|
+
logger.warn('Theme overlay rejected', {
|
|
2084
|
+
component: 'ThemeProvider',
|
|
2085
|
+
action: 'applyOverlays',
|
|
2086
|
+
theme: themeName,
|
|
2087
|
+
errors: layered.errors,
|
|
2088
|
+
});
|
|
2089
|
+
}
|
|
1862
2090
|
const normalizedConfig = {
|
|
1863
|
-
...config,
|
|
1864
|
-
themes: applySchemePreferences(config.themes),
|
|
2091
|
+
...layered.config,
|
|
2092
|
+
themes: applySchemePreferences(layered.config.themes),
|
|
1865
2093
|
};
|
|
1866
2094
|
await themeService.configureRuntime(normalizedConfig, themeName, { blocking });
|
|
1867
2095
|
};
|
|
@@ -1924,6 +2152,7 @@ function provideRuntimeTheme(configPath, options) {
|
|
|
1924
2152
|
});
|
|
1925
2153
|
return;
|
|
1926
2154
|
}
|
|
2155
|
+
overlays = await loadOverlays(themeConfig.overlays);
|
|
1927
2156
|
const themePaths = themeConfig.themes ?? [];
|
|
1928
2157
|
const themeEntries = new Map();
|
|
1929
2158
|
const availableThemes = [];
|
|
@@ -2041,6 +2270,7 @@ function provideRuntimeTheme(configPath, options) {
|
|
|
2041
2270
|
? refreshedEntries
|
|
2042
2271
|
: new Map([...refreshedEntries].filter(([name]) => updatedThemes.includes(name)));
|
|
2043
2272
|
if (configHashChanged) {
|
|
2273
|
+
overlays = await loadOverlays(refreshedConfig.data.overlays, true);
|
|
2044
2274
|
themeService.applyRuntimeConfig({
|
|
2045
2275
|
availableThemes: refreshedAvailableThemes,
|
|
2046
2276
|
defaultTheme: refreshedDefaultTheme,
|
|
@@ -2127,5 +2357,5 @@ function provideSchemeFavicon(config) {
|
|
|
2127
2357
|
* Generated bundle index. Do not edit.
|
|
2128
2358
|
*/
|
|
2129
2359
|
|
|
2130
|
-
export { DEFAULT_BASE_THEME, DEFAULT_SCHEME, FALLBACK_RUNTIME_THEME_CONFIG, SCHEME_FAVICON_CONFIG, SchemeFaviconService, THEME_SCHEMA_VERSION, ThemeAssetsService, ThemeDomService, ThemeSchemeService, ThemeService, ThemeStorageService, VALID_SCHEMES, applySchemePreferences, buildThemeIdentifier, formatSchemeName, formatThemeName, hasLocalStorage, isThemeAvailable, isValidScheme, parseThemeIdentifier, provideRuntimeTheme, provideSchemeFavicon, resolveDefaultTheme, supportsMediaQuery, validateThemeConfig };
|
|
2360
|
+
export { DEFAULT_BASE_THEME, DEFAULT_SCHEME, FALLBACK_RUNTIME_THEME_CONFIG, SCHEME_FAVICON_CONFIG, SchemeFaviconService, THEME_OVERLAY_CORE_TOKENS, THEME_OVERLAY_OVERRIDABLE_PREFIXES, THEME_OVERLAY_SCHEMA_VERSION, THEME_SCHEMA_VERSION, ThemeAssetsService, ThemeDomService, ThemeSchemeService, ThemeService, ThemeStorageService, VALID_SCHEMES, applySchemePreferences, applyThemeOverlays, buildThemeIdentifier, formatSchemeName, formatThemeName, hasLocalStorage, isThemeAvailable, isValidScheme, mergeThemeOverlay, parseThemeIdentifier, provideRuntimeTheme, provideSchemeFavicon, resolveDefaultTheme, supportsMediaQuery, themeOverlayAppliesTo, validateThemeConfig, validateThemeOverlay, validateThemeOverlayFor };
|
|
2131
2361
|
//# sourceMappingURL=sixbell-telco-sdk-utils-theme.mjs.map
|