@ship-ui/core 0.16.9 → 0.16.10

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.
@@ -3,6 +3,7 @@ import { inject, ElementRef, Renderer2, ChangeDetectionStrategy, Component, sign
3
3
  import { isPlatformBrowser, JsonPipe, DatePipe, isPlatformServer, NgTemplateOutlet } from '@angular/common';
4
4
  import { NgModel } from '@angular/forms';
5
5
  import { SIGNAL } from '@angular/core/primitives/signals';
6
+ import { ShipIcon as ShipIcon$1, ShipButton as ShipButton$1 } from 'ship-ui';
6
7
 
7
8
  const iconTypes = ['bold', 'thin', 'light', 'fill', 'duotone'];
8
9
  class ShipIcon {
@@ -6090,6 +6091,116 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImpor
6090
6091
  }]
6091
6092
  }] });
6092
6093
 
6094
+ const THEME_ORDER = ['light', 'dark', null];
6095
+ const WINDOW = new InjectionToken('WindowToken', {
6096
+ providedIn: 'root',
6097
+ factory: () => (typeof window !== 'undefined' ? window : {}),
6098
+ });
6099
+ class ShipThemeState {
6100
+ constructor() {
6101
+ this.#document = inject(DOCUMENT);
6102
+ this.#window = inject(WINDOW);
6103
+ this.#platformId = inject(PLATFORM_ID);
6104
+ this.#storedDarkMode = this.localStorage()?.getItem('shipTheme');
6105
+ this.#theme = signal(this.#storedDarkMode, ...(ngDevMode ? [{ debugName: "#theme" }] : []));
6106
+ this.theme = this.#theme.asReadonly();
6107
+ this.darkModeEffect = effect(() => {
6108
+ const theme = this.#theme();
6109
+ if (theme === null) {
6110
+ this.#document.documentElement.classList.remove('dark');
6111
+ this.#document.documentElement.classList.remove('light');
6112
+ return;
6113
+ }
6114
+ if (theme === 'dark') {
6115
+ this.#document.documentElement.classList.add('dark');
6116
+ this.#document.documentElement.classList.remove('light');
6117
+ }
6118
+ else {
6119
+ this.#document.documentElement.classList.add('light');
6120
+ this.#document.documentElement.classList.remove('dark');
6121
+ }
6122
+ }, ...(ngDevMode ? [{ debugName: "darkModeEffect" }] : []));
6123
+ }
6124
+ #document;
6125
+ #window;
6126
+ #platformId;
6127
+ #storedDarkMode;
6128
+ #theme;
6129
+ localStorage() {
6130
+ if (isPlatformServer(this.#platformId))
6131
+ return null;
6132
+ return this.#window.localStorage;
6133
+ }
6134
+ toggleTheme() {
6135
+ const nextTheme = this.#theme() === null ? THEME_ORDER[0] : THEME_ORDER[THEME_ORDER.indexOf(this.#theme()) + 1];
6136
+ this.setTheme(nextTheme);
6137
+ }
6138
+ setTheme(theme) {
6139
+ if (theme === null) {
6140
+ this.localStorage()?.removeItem('shipTheme');
6141
+ this.#theme.set(null);
6142
+ return;
6143
+ }
6144
+ this.localStorage()?.setItem('shipTheme', theme);
6145
+ this.#theme.set(theme);
6146
+ }
6147
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: ShipThemeState, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
6148
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: ShipThemeState, providedIn: 'root' }); }
6149
+ }
6150
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: ShipThemeState, decorators: [{
6151
+ type: Injectable,
6152
+ args: [{
6153
+ providedIn: 'root',
6154
+ }]
6155
+ }] });
6156
+
6157
+ class ShipThemeToggle {
6158
+ constructor() {
6159
+ this.#themeState = inject(ShipThemeState);
6160
+ this.theme = this.#themeState.theme;
6161
+ }
6162
+ #themeState;
6163
+ toggleTheme() {
6164
+ this.#themeState.toggleTheme();
6165
+ }
6166
+ setTheme(theme) {
6167
+ this.#themeState.setTheme(theme);
6168
+ }
6169
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: ShipThemeToggle, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
6170
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.9", type: ShipThemeToggle, isStandalone: true, selector: "ship-theme-toggle", ngImport: i0, template: `
6171
+ <button shButton class="small" (click)="toggleTheme()">
6172
+ @if (theme() === 'dark') {
6173
+ <sh-icon>moon-bold</sh-icon>
6174
+ } @else if (theme() === 'light') {
6175
+ <sh-icon>sun-bold</sh-icon>
6176
+ } @else if (theme() === null) {
6177
+ <sh-icon class="small-icon">sun-bold</sh-icon>
6178
+ <sh-icon class="small-icon">moon-bold</sh-icon>
6179
+ }
6180
+ </button>
6181
+ `, isInline: true, dependencies: [{ kind: "component", type: ShipIcon$1, selector: "sh-icon" }, { kind: "component", type: ShipButton$1, selector: "[shButton]" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
6182
+ }
6183
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: ShipThemeToggle, decorators: [{
6184
+ type: Component,
6185
+ args: [{
6186
+ selector: 'ship-theme-toggle',
6187
+ imports: [ShipIcon$1, ShipButton$1],
6188
+ template: `
6189
+ <button shButton class="small" (click)="toggleTheme()">
6190
+ @if (theme() === 'dark') {
6191
+ <sh-icon>moon-bold</sh-icon>
6192
+ } @else if (theme() === 'light') {
6193
+ <sh-icon>sun-bold</sh-icon>
6194
+ } @else if (theme() === null) {
6195
+ <sh-icon class="small-icon">sun-bold</sh-icon>
6196
+ <sh-icon class="small-icon">moon-bold</sh-icon>
6197
+ }
6198
+ </button>
6199
+ `,
6200
+ changeDetection: ChangeDetectionStrategy.OnPush,
6201
+ }]
6202
+ }] });
6203
+
6093
6204
  class ShipToggleCard {
6094
6205
  constructor() {
6095
6206
  this.isActive = model(false, ...(ngDevMode ? [{ debugName: "isActive" }] : []));
@@ -6724,5 +6835,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImpor
6724
6835
  * Generated bundle index. Do not edit.
6725
6836
  */
6726
6837
 
6727
- export { GridSortable, SHIP_CONFIG, ShipAlert, ShipAlertContainer, ShipAlertModule, ShipAlertService, ShipBlueprint, ShipButton, ShipButtonGroup, ShipCard, ShipCheckbox, ShipChip, ShipColorPicker, ShipDatepicker, ShipDatepickerInput, ShipDaterangeInput, ShipDialog, ShipDialogService, ShipDivider, ShipEventCard, ShipFileDragDrop, ShipFileUpload, ShipFormField, ShipFormFieldExperimental, ShipIcon, ShipInputMask, ShipList, ShipMenu, ShipPopover, ShipPreventWheel, ShipProgressBar, ShipRadio, ShipRangeSlider, ShipResize, ShipSelect, ShipSidenav, ShipSort, ShipSortable, ShipSpinner, ShipStepper, ShipStickyColumns, ShipTable, ShipTabs, ShipToggle, ShipToggleCard, ShipTooltip, ShipTooltipWrapper, ShipVirtualScroll, TEST_NODES, moveIndex, watchHostClass };
6838
+ export { GridSortable, SHIP_CONFIG, ShipAlert, ShipAlertContainer, ShipAlertModule, ShipAlertService, ShipBlueprint, ShipButton, ShipButtonGroup, ShipCard, ShipCheckbox, ShipChip, ShipColorPicker, ShipDatepicker, ShipDatepickerInput, ShipDaterangeInput, ShipDialog, ShipDialogService, ShipDivider, ShipEventCard, ShipFileDragDrop, ShipFileUpload, ShipFormField, ShipFormFieldExperimental, ShipIcon, ShipInputMask, ShipList, ShipMenu, ShipPopover, ShipPreventWheel, ShipProgressBar, ShipRadio, ShipRangeSlider, ShipResize, ShipSelect, ShipSidenav, ShipSort, ShipSortable, ShipSpinner, ShipStepper, ShipStickyColumns, ShipTable, ShipTabs, ShipThemeToggle, ShipToggle, ShipToggleCard, ShipTooltip, ShipTooltipWrapper, ShipVirtualScroll, TEST_NODES, moveIndex, watchHostClass };
6728
6839
  //# sourceMappingURL=ship-ui-core.mjs.map