@ngbase/adk 0.1.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/README.md +57 -0
- package/a11y/accessibility-group.d.ts +49 -0
- package/a11y/accessibility-item.d.ts +49 -0
- package/a11y/accessibility.service.d.ts +17 -0
- package/a11y/autofocus.d.ts +12 -0
- package/a11y/focus-trap.d.ts +15 -0
- package/a11y/index.d.ts +5 -0
- package/a11y/public-api.d.ts +4 -0
- package/accordion/accordion-content.d.ts +8 -0
- package/accordion/accordion-group.d.ts +10 -0
- package/accordion/accordion-header.d.ts +7 -0
- package/accordion/accordion-item.d.ts +10 -0
- package/accordion/index.d.ts +5 -0
- package/accordion/public-api.d.ts +4 -0
- package/autocomplete/autocomplete-input.d.ts +21 -0
- package/autocomplete/autocomplete.d.ts +25 -0
- package/autocomplete/index.d.ts +5 -0
- package/autocomplete/public-api.d.ts +2 -0
- package/avatar/avatar.d.ts +22 -0
- package/avatar/index.d.ts +5 -0
- package/avatar/public-api.d.ts +1 -0
- package/bidi/direction.service.d.ts +14 -0
- package/bidi/index.d.ts +5 -0
- package/bidi/public-api.d.ts +1 -0
- package/breadcrumb/breadcrumb-link.d.ts +7 -0
- package/breadcrumb/breadcrumb-separator.d.ts +10 -0
- package/breadcrumb/breadcrumb.d.ts +12 -0
- package/breadcrumb/breadcrumbs.d.ts +7 -0
- package/breadcrumb/index.d.ts +5 -0
- package/breadcrumb/public-api.d.ts +4 -0
- package/cache/cache-config.d.ts +22 -0
- package/cache/cache.d.ts +17 -0
- package/cache/cache.interecptor.d.ts +2 -0
- package/cache/index.d.ts +5 -0
- package/cache/public-api.d.ts +3 -0
- package/carousel/carousel-item.d.ts +7 -0
- package/carousel/carousel-next.d.ts +8 -0
- package/carousel/carousel.d.ts +61 -0
- package/carousel/index.d.ts +5 -0
- package/carousel/public-api.d.ts +3 -0
- package/checkbox/checkbox.d.ts +22 -0
- package/checkbox/index.d.ts +5 -0
- package/checkbox/public-api.d.ts +1 -0
- package/chip/chip-group.d.ts +7 -0
- package/chip/chip.d.ts +19 -0
- package/chip/index.d.ts +5 -0
- package/chip/public-api.d.ts +2 -0
- package/clipboard/clipboard.d.ts +7 -0
- package/clipboard/index.d.ts +5 -0
- package/clipboard/public-api.d.ts +1 -0
- package/collections/SelectionModel.d.ts +14 -0
- package/collections/index.d.ts +5 -0
- package/collections/public-api.d.ts +1 -0
- package/color-picker/color-input.d.ts +16 -0
- package/color-picker/color-picker-trigger.d.ts +30 -0
- package/color-picker/color-picker.d.ts +72 -0
- package/color-picker/index.d.ts +5 -0
- package/color-picker/public-api.d.ts +3 -0
- package/color-picker/utils.d.ts +21 -0
- package/cookies/cookie.service.d.ts +32 -0
- package/cookies/index.d.ts +5 -0
- package/cookies/public-api.d.ts +1 -0
- package/datepicker/calendar.d.ts +121 -0
- package/datepicker/datepicker-trigger.d.ts +49 -0
- package/datepicker/datepicker.d.ts +54 -0
- package/datepicker/index.d.ts +5 -0
- package/datepicker/native-date-adapter.d.ts +33 -0
- package/datepicker/public-api.d.ts +5 -0
- package/datepicker/time.d.ts +42 -0
- package/dialog/dialog.animation.d.ts +3 -0
- package/dialog/dialog.d.ts +49 -0
- package/dialog/dialog.service.d.ts +7 -0
- package/dialog/index.d.ts +5 -0
- package/dialog/public-api.d.ts +3 -0
- package/drag/drag-drop.d.ts +37 -0
- package/drag/drag-move.d.ts +17 -0
- package/drag/drag.d.ts +53 -0
- package/drag/index.d.ts +5 -0
- package/drag/public-api.d.ts +3 -0
- package/fesm2022/ngbase-adk-a11y.mjs +617 -0
- package/fesm2022/ngbase-adk-a11y.mjs.map +1 -0
- package/fesm2022/ngbase-adk-accordion.mjs +117 -0
- package/fesm2022/ngbase-adk-accordion.mjs.map +1 -0
- package/fesm2022/ngbase-adk-autocomplete.mjs +150 -0
- package/fesm2022/ngbase-adk-autocomplete.mjs.map +1 -0
- package/fesm2022/ngbase-adk-avatar.mjs +69 -0
- package/fesm2022/ngbase-adk-avatar.mjs.map +1 -0
- package/fesm2022/ngbase-adk-bidi.mjs +42 -0
- package/fesm2022/ngbase-adk-bidi.mjs.map +1 -0
- package/fesm2022/ngbase-adk-breadcrumb.mjs +103 -0
- package/fesm2022/ngbase-adk-breadcrumb.mjs.map +1 -0
- package/fesm2022/ngbase-adk-cache.mjs +127 -0
- package/fesm2022/ngbase-adk-cache.mjs.map +1 -0
- package/fesm2022/ngbase-adk-carousel.mjs +337 -0
- package/fesm2022/ngbase-adk-carousel.mjs.map +1 -0
- package/fesm2022/ngbase-adk-checkbox.mjs +78 -0
- package/fesm2022/ngbase-adk-checkbox.mjs.map +1 -0
- package/fesm2022/ngbase-adk-chip.mjs +60 -0
- package/fesm2022/ngbase-adk-chip.mjs.map +1 -0
- package/fesm2022/ngbase-adk-clipboard.mjs +41 -0
- package/fesm2022/ngbase-adk-clipboard.mjs.map +1 -0
- package/fesm2022/ngbase-adk-collections.mjs +39 -0
- package/fesm2022/ngbase-adk-collections.mjs.map +1 -0
- package/fesm2022/ngbase-adk-color-picker.mjs +580 -0
- package/fesm2022/ngbase-adk-color-picker.mjs.map +1 -0
- package/fesm2022/ngbase-adk-cookies.mjs +81 -0
- package/fesm2022/ngbase-adk-cookies.mjs.map +1 -0
- package/fesm2022/ngbase-adk-datepicker.mjs +1130 -0
- package/fesm2022/ngbase-adk-datepicker.mjs.map +1 -0
- package/fesm2022/ngbase-adk-dialog.mjs +223 -0
- package/fesm2022/ngbase-adk-dialog.mjs.map +1 -0
- package/fesm2022/ngbase-adk-drag.mjs +406 -0
- package/fesm2022/ngbase-adk-drag.mjs.map +1 -0
- package/fesm2022/ngbase-adk-form-field.mjs +364 -0
- package/fesm2022/ngbase-adk-form-field.mjs.map +1 -0
- package/fesm2022/ngbase-adk-hover-card.mjs +79 -0
- package/fesm2022/ngbase-adk-hover-card.mjs.map +1 -0
- package/fesm2022/ngbase-adk-icon.mjs +90 -0
- package/fesm2022/ngbase-adk-icon.mjs.map +1 -0
- package/fesm2022/ngbase-adk-inline-edit.mjs +127 -0
- package/fesm2022/ngbase-adk-inline-edit.mjs.map +1 -0
- package/fesm2022/ngbase-adk-jwt.mjs +90 -0
- package/fesm2022/ngbase-adk-jwt.mjs.map +1 -0
- package/fesm2022/ngbase-adk-keys.mjs +219 -0
- package/fesm2022/ngbase-adk-keys.mjs.map +1 -0
- package/fesm2022/ngbase-adk-layout.mjs +100 -0
- package/fesm2022/ngbase-adk-layout.mjs.map +1 -0
- package/fesm2022/ngbase-adk-list.mjs +110 -0
- package/fesm2022/ngbase-adk-list.mjs.map +1 -0
- package/fesm2022/ngbase-adk-mask.mjs +234 -0
- package/fesm2022/ngbase-adk-mask.mjs.map +1 -0
- package/fesm2022/ngbase-adk-menu.mjs +546 -0
- package/fesm2022/ngbase-adk-menu.mjs.map +1 -0
- package/fesm2022/ngbase-adk-network.mjs +90 -0
- package/fesm2022/ngbase-adk-network.mjs.map +1 -0
- package/fesm2022/ngbase-adk-pagination.mjs +187 -0
- package/fesm2022/ngbase-adk-pagination.mjs.map +1 -0
- package/fesm2022/ngbase-adk-popover.mjs +953 -0
- package/fesm2022/ngbase-adk-popover.mjs.map +1 -0
- package/fesm2022/ngbase-adk-portal.mjs +279 -0
- package/fesm2022/ngbase-adk-portal.mjs.map +1 -0
- package/fesm2022/ngbase-adk-progress.mjs +57 -0
- package/fesm2022/ngbase-adk-progress.mjs.map +1 -0
- package/fesm2022/ngbase-adk-radio.mjs +129 -0
- package/fesm2022/ngbase-adk-radio.mjs.map +1 -0
- package/fesm2022/ngbase-adk-resizable.mjs +367 -0
- package/fesm2022/ngbase-adk-resizable.mjs.map +1 -0
- package/fesm2022/ngbase-adk-scroll-area.mjs +232 -0
- package/fesm2022/ngbase-adk-scroll-area.mjs.map +1 -0
- package/fesm2022/ngbase-adk-select.mjs +599 -0
- package/fesm2022/ngbase-adk-select.mjs.map +1 -0
- package/fesm2022/ngbase-adk-selectable.mjs +79 -0
- package/fesm2022/ngbase-adk-selectable.mjs.map +1 -0
- package/fesm2022/ngbase-adk-sidenav.mjs +209 -0
- package/fesm2022/ngbase-adk-sidenav.mjs.map +1 -0
- package/fesm2022/ngbase-adk-slider.mjs +337 -0
- package/fesm2022/ngbase-adk-slider.mjs.map +1 -0
- package/fesm2022/ngbase-adk-sonner.mjs +176 -0
- package/fesm2022/ngbase-adk-sonner.mjs.map +1 -0
- package/fesm2022/ngbase-adk-stepper.mjs +211 -0
- package/fesm2022/ngbase-adk-stepper.mjs.map +1 -0
- package/fesm2022/ngbase-adk-switch.mjs +115 -0
- package/fesm2022/ngbase-adk-switch.mjs.map +1 -0
- package/fesm2022/ngbase-adk-table.mjs +348 -0
- package/fesm2022/ngbase-adk-table.mjs.map +1 -0
- package/fesm2022/ngbase-adk-tabs.mjs +386 -0
- package/fesm2022/ngbase-adk-tabs.mjs.map +1 -0
- package/fesm2022/ngbase-adk-test.mjs +267 -0
- package/fesm2022/ngbase-adk-test.mjs.map +1 -0
- package/fesm2022/ngbase-adk-toggle-group.mjs +114 -0
- package/fesm2022/ngbase-adk-toggle-group.mjs.map +1 -0
- package/fesm2022/ngbase-adk-toggle.mjs +48 -0
- package/fesm2022/ngbase-adk-toggle.mjs.map +1 -0
- package/fesm2022/ngbase-adk-tooltip.mjs +237 -0
- package/fesm2022/ngbase-adk-tooltip.mjs.map +1 -0
- package/fesm2022/ngbase-adk-tour.mjs +312 -0
- package/fesm2022/ngbase-adk-tour.mjs.map +1 -0
- package/fesm2022/ngbase-adk-translate.mjs +162 -0
- package/fesm2022/ngbase-adk-translate.mjs.map +1 -0
- package/fesm2022/ngbase-adk-tree.mjs +301 -0
- package/fesm2022/ngbase-adk-tree.mjs.map +1 -0
- package/fesm2022/ngbase-adk-utils.mjs +228 -0
- package/fesm2022/ngbase-adk-utils.mjs.map +1 -0
- package/fesm2022/ngbase-adk-virtualizer.mjs +198 -0
- package/fesm2022/ngbase-adk-virtualizer.mjs.map +1 -0
- package/fesm2022/ngbase-adk.mjs +6 -0
- package/fesm2022/ngbase-adk.mjs.map +1 -0
- package/form-field/auto-height.d.ts +9 -0
- package/form-field/error.d.ts +18 -0
- package/form-field/form-field.d.ts +14 -0
- package/form-field/index.d.ts +5 -0
- package/form-field/input.d.ts +16 -0
- package/form-field/label.d.ts +7 -0
- package/form-field/otp.d.ts +48 -0
- package/form-field/public-api.d.ts +6 -0
- package/hover-card/hover-card.d.ts +18 -0
- package/hover-card/index.d.ts +5 -0
- package/hover-card/public-api.d.ts +1 -0
- package/icon/icon.d.ts +12 -0
- package/icon/icon.service.d.ts +12 -0
- package/icon/index.d.ts +5 -0
- package/icon/public-api.d.ts +2 -0
- package/index.d.ts +5 -0
- package/inline-edit/index.d.ts +5 -0
- package/inline-edit/inline-edit.d.ts +47 -0
- package/inline-edit/public-api.d.ts +1 -0
- package/jwt/index.d.ts +5 -0
- package/jwt/jwt.service.d.ts +27 -0
- package/jwt/public-api.d.ts +1 -0
- package/keys/index.d.ts +5 -0
- package/keys/keys.service.d.ts +13 -0
- package/keys/public-api.d.ts +2 -0
- package/keys/shortcuts.service.d.ts +38 -0
- package/layout/index.d.ts +5 -0
- package/layout/layout.d.ts +16 -0
- package/layout/public-api.d.ts +1 -0
- package/list/index.d.ts +5 -0
- package/list/list.d.ts +20 -0
- package/list/list.directive.d.ts +12 -0
- package/list/public-api.d.ts +2 -0
- package/mask/index.d.ts +5 -0
- package/mask/mask-pipe.d.ts +7 -0
- package/mask/mask.d.ts +25 -0
- package/mask/public-api.d.ts +2 -0
- package/menu/context-menu.d.ts +21 -0
- package/menu/index.d.ts +5 -0
- package/menu/mention.d.ts +18 -0
- package/menu/menu-trigger.d.ts +34 -0
- package/menu/menu.d.ts +52 -0
- package/menu/navigation-menu.d.ts +19 -0
- package/menu/public-api.d.ts +5 -0
- package/network/index.d.ts +5 -0
- package/network/network.interceptor.d.ts +6 -0
- package/network/network.service.d.ts +18 -0
- package/network/public-api.d.ts +2 -0
- package/package.json +247 -0
- package/pagination/index.d.ts +5 -0
- package/pagination/pagination.d.ts +28 -0
- package/pagination/public-api.d.ts +1 -0
- package/popover/base-popover.service.d.ts +16 -0
- package/popover/index.d.ts +5 -0
- package/popover/popover-trigger.d.ts +21 -0
- package/popover/popover.d.ts +50 -0
- package/popover/popover.service.d.ts +42 -0
- package/popover/public-api.d.ts +5 -0
- package/popover/utils.d.ts +85 -0
- package/portal/dialog-ref.d.ts +71 -0
- package/portal/index.d.ts +5 -0
- package/portal/portal-base.service.d.ts +19 -0
- package/portal/portal-close.directive.d.ts +8 -0
- package/portal/portal.component.d.ts +7 -0
- package/portal/portal.service.d.ts +16 -0
- package/portal/public-api.d.ts +5 -0
- package/progress/index.d.ts +5 -0
- package/progress/progress.d.ts +13 -0
- package/progress/public-api.d.ts +1 -0
- package/public-api.d.ts +2 -0
- package/radio/index.d.ts +5 -0
- package/radio/public-api.d.ts +2 -0
- package/radio/radio-group.d.ts +19 -0
- package/radio/radio.d.ts +22 -0
- package/resizable/index.d.ts +5 -0
- package/resizable/public-api.d.ts +2 -0
- package/resizable/resizable-group.d.ts +22 -0
- package/resizable/resizable.d.ts +50 -0
- package/scroll-area/index.d.ts +5 -0
- package/scroll-area/public-api.d.ts +1 -0
- package/scroll-area/scroll-area.d.ts +56 -0
- package/select/index.d.ts +5 -0
- package/select/list-selection.d.ts +7 -0
- package/select/option-group.d.ts +7 -0
- package/select/option.d.ts +25 -0
- package/select/public-api.d.ts +6 -0
- package/select/select-base.d.ts +64 -0
- package/select/select-input.d.ts +23 -0
- package/select/select.d.ts +50 -0
- package/selectable/index.d.ts +5 -0
- package/selectable/public-api.d.ts +2 -0
- package/selectable/selectable-item.d.ts +12 -0
- package/selectable/selectable.d.ts +19 -0
- package/sidenav/index.d.ts +5 -0
- package/sidenav/public-api.d.ts +3 -0
- package/sidenav/sidenav-header.d.ts +31 -0
- package/sidenav/sidenav.d.ts +23 -0
- package/sidenav/sidenav.service.d.ts +18 -0
- package/slider/index.d.ts +5 -0
- package/slider/public-api.d.ts +1 -0
- package/slider/slider.d.ts +73 -0
- package/sonner/index.d.ts +5 -0
- package/sonner/public-api.d.ts +2 -0
- package/sonner/sonner.d.ts +24 -0
- package/sonner/sonner.service.d.ts +21 -0
- package/stepper/animation.d.ts +1 -0
- package/stepper/index.d.ts +5 -0
- package/stepper/public-api.d.ts +3 -0
- package/stepper/step.d.ts +24 -0
- package/stepper/stepper.d.ts +26 -0
- package/switch/index.d.ts +5 -0
- package/switch/public-api.d.ts +1 -0
- package/switch/switch.d.ts +44 -0
- package/table/body-cell.d.ts +11 -0
- package/table/body-row.d.ts +21 -0
- package/table/column.d.ts +10 -0
- package/table/head-cell.d.ts +12 -0
- package/table/head-row.d.ts +21 -0
- package/table/index.d.ts +5 -0
- package/table/public-api.d.ts +8 -0
- package/table/table.d.ts +32 -0
- package/tabs/index.d.ts +5 -0
- package/tabs/public-api.d.ts +2 -0
- package/tabs/tab-group.d.ts +52 -0
- package/tabs/tab.d.ts +31 -0
- package/test/index.d.ts +5 -0
- package/test/public-api.d.ts +1 -0
- package/test/utils.d.ts +62 -0
- package/toggle/index.d.ts +5 -0
- package/toggle/public-api.d.ts +1 -0
- package/toggle/toggle.d.ts +13 -0
- package/toggle-group/index.d.ts +5 -0
- package/toggle-group/public-api.d.ts +2 -0
- package/toggle-group/toggle-group.d.ts +25 -0
- package/toggle-group/toggle-item.d.ts +14 -0
- package/tooltip/index.d.ts +5 -0
- package/tooltip/public-api.d.ts +2 -0
- package/tooltip/tooltip.d.ts +20 -0
- package/tooltip/tooltip.directive.d.ts +34 -0
- package/tooltip/tooltip.service.d.ts +26 -0
- package/tour/animation.d.ts +2 -0
- package/tour/index.d.ts +5 -0
- package/tour/public-api.d.ts +5 -0
- package/tour/tour-base.d.ts +21 -0
- package/tour/tour-step.d.ts +11 -0
- package/tour/tour.d.ts +9 -0
- package/tour/tour.service.d.ts +30 -0
- package/translate/config.d.ts +16 -0
- package/translate/index.d.ts +5 -0
- package/translate/public-api.d.ts +3 -0
- package/translate/translate.d.ts +11 -0
- package/translate/translate.service.d.ts +31 -0
- package/tree/index.d.ts +5 -0
- package/tree/public-api.d.ts +3 -0
- package/tree/tree-node.d.ts +28 -0
- package/tree/tree-toggle.d.ts +16 -0
- package/tree/tree.d.ts +55 -0
- package/utils/animation.d.ts +3 -0
- package/utils/disposals.d.ts +7 -0
- package/utils/index.d.ts +5 -0
- package/utils/number-only.d.ts +22 -0
- package/utils/public-api.d.ts +6 -0
- package/utils/range.pipe.d.ts +7 -0
- package/utils/ssr.d.ts +2 -0
- package/utils/utils.d.ts +27 -0
- package/virtualizer/index.d.ts +5 -0
- package/virtualizer/public-api.d.ts +1 -0
- package/virtualizer/virtualizer.d.ts +42 -0
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Directive, Component, inject, ElementRef, viewChild, output, input, afterNextRender, InjectionToken, Injector, model, effect, untracked } from '@angular/core';
|
|
3
|
+
import * as i1 from '@ngbase/adk/drag';
|
|
4
|
+
import { Drag } from '@ngbase/adk/drag';
|
|
5
|
+
import { DialogRef } from '@ngbase/adk/portal';
|
|
6
|
+
import { ngbPopoverPortal } from '@ngbase/adk/popover';
|
|
7
|
+
import { provideValueAccessor } from '@ngbase/adk/utils';
|
|
8
|
+
|
|
9
|
+
const MAX_RGB = 255;
|
|
10
|
+
const MAX_HUE = 360;
|
|
11
|
+
const MAX_PERCENTAGE = 100;
|
|
12
|
+
function hexToRgb(hex) {
|
|
13
|
+
// Remove the hash at the start if it's there
|
|
14
|
+
hex = hex.replace(/^#/, '');
|
|
15
|
+
// Check for valid hex formats
|
|
16
|
+
if (!/^([0-9A-Fa-f]{3}|[0-9A-Fa-f]{4}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/.test(hex)) {
|
|
17
|
+
throw new Error('Invalid hex color format');
|
|
18
|
+
}
|
|
19
|
+
let r, g, b, a = 1;
|
|
20
|
+
if (hex.length === 3 || hex.length === 4) {
|
|
21
|
+
r = parseInt(hex[0] + hex[0], 16);
|
|
22
|
+
g = parseInt(hex[1] + hex[1], 16);
|
|
23
|
+
b = parseInt(hex[2] + hex[2], 16);
|
|
24
|
+
if (hex.length === 4) {
|
|
25
|
+
a = parseInt(hex[3] + hex[3], 16) / 255;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else if (hex.length === 6 || hex.length === 8) {
|
|
29
|
+
r = parseInt(hex.slice(0, 2), 16);
|
|
30
|
+
g = parseInt(hex.slice(2, 4), 16);
|
|
31
|
+
b = parseInt(hex.slice(4, 6), 16);
|
|
32
|
+
if (hex.length === 8) {
|
|
33
|
+
a = parseInt(hex.slice(6, 8), 16) / 255;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
throw new Error('Invalid hex color format');
|
|
38
|
+
}
|
|
39
|
+
return [r, g, b, roundTo2Decimals(a)];
|
|
40
|
+
}
|
|
41
|
+
function rgbaToHsb(r, g, b, a = 1) {
|
|
42
|
+
validateRgba(r, g, b, a);
|
|
43
|
+
r /= 255;
|
|
44
|
+
g /= 255;
|
|
45
|
+
b /= 255;
|
|
46
|
+
const max = Math.max(r, g, b);
|
|
47
|
+
const min = Math.min(r, g, b);
|
|
48
|
+
let h = 0;
|
|
49
|
+
const d = max - min;
|
|
50
|
+
const s = max === 0 ? 0 : d / max;
|
|
51
|
+
const v = max;
|
|
52
|
+
if (max !== min) {
|
|
53
|
+
switch (max) {
|
|
54
|
+
case r:
|
|
55
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
56
|
+
break;
|
|
57
|
+
case g:
|
|
58
|
+
h = (b - r) / d + 2;
|
|
59
|
+
break;
|
|
60
|
+
case b:
|
|
61
|
+
h = (r - g) / d + 4;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
h /= 6;
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
h: roundNum(h * 360),
|
|
68
|
+
s: roundNum(s * 100),
|
|
69
|
+
b: roundNum(v * 100),
|
|
70
|
+
a: roundTo2Decimals(a),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function hexToHsb(hex) {
|
|
74
|
+
const [r, g, b, a] = hexToRgb(hex);
|
|
75
|
+
const { h, s, b: brightness, a: alpha } = rgbaToHsb(r, g, b, a);
|
|
76
|
+
return [roundNum(h), roundNum(s), roundNum(brightness), roundTo2Decimals(alpha)];
|
|
77
|
+
}
|
|
78
|
+
function rgbToHsl(r, g, b) {
|
|
79
|
+
validateRgb(r, g, b);
|
|
80
|
+
r /= MAX_RGB;
|
|
81
|
+
g /= MAX_RGB;
|
|
82
|
+
b /= MAX_RGB;
|
|
83
|
+
const max = Math.max(r, g, b);
|
|
84
|
+
const min = Math.min(r, g, b);
|
|
85
|
+
let h = 0;
|
|
86
|
+
let s = 0;
|
|
87
|
+
const l = (max + min) / 2;
|
|
88
|
+
const d = max - min;
|
|
89
|
+
if (d) {
|
|
90
|
+
s = d / (1 - Math.abs(2 * l - 1));
|
|
91
|
+
switch (max) {
|
|
92
|
+
case r:
|
|
93
|
+
h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
|
|
94
|
+
break;
|
|
95
|
+
case g:
|
|
96
|
+
h = ((b - r) / d + 2) / 6;
|
|
97
|
+
break;
|
|
98
|
+
case b:
|
|
99
|
+
h = ((r - g) / d + 4) / 6;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
h: roundNum(h * MAX_HUE),
|
|
105
|
+
s: roundNum(s * MAX_PERCENTAGE),
|
|
106
|
+
l: roundNum(l * MAX_PERCENTAGE),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function parseRgba(rgba) {
|
|
110
|
+
const matches = rgba.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/);
|
|
111
|
+
if (!matches) {
|
|
112
|
+
throw new Error('Invalid RGBA string format');
|
|
113
|
+
}
|
|
114
|
+
const [, r, g, b, a] = matches;
|
|
115
|
+
return [parseInt(r, 10), parseInt(g, 10), parseInt(b, 10), a ? parseFloat(a) : 1];
|
|
116
|
+
}
|
|
117
|
+
function parseHsba(hsb) {
|
|
118
|
+
const matches = hsb.match(/^hsba?\((\d+),\s*(\d+)%,\s*(\d+)%(?:,\s*(\d+(?:\.\d+)?))?\)$/);
|
|
119
|
+
if (!matches) {
|
|
120
|
+
throw new Error('Invalid HSBA string format');
|
|
121
|
+
}
|
|
122
|
+
const [, h, s, b, a] = matches;
|
|
123
|
+
return [parseInt(h, 10), parseInt(s, 10), parseInt(b, 10), a ? parseFloat(a) : 1];
|
|
124
|
+
}
|
|
125
|
+
function hsbToHsl(h, s, b) {
|
|
126
|
+
validateHsb(h, s, b);
|
|
127
|
+
s /= MAX_PERCENTAGE;
|
|
128
|
+
b /= MAX_PERCENTAGE;
|
|
129
|
+
const l = b * (1 - s / 2);
|
|
130
|
+
const saturation = l === 0 || l === 1 ? 0 : (b - l) / Math.min(l, 1 - l);
|
|
131
|
+
return [roundNum(h), roundNum(saturation * MAX_PERCENTAGE), roundNum(l * MAX_PERCENTAGE)];
|
|
132
|
+
}
|
|
133
|
+
function hslaToHsba(h, s, l, a = 1) {
|
|
134
|
+
validateHsl(h, s, l);
|
|
135
|
+
validateAlpha(a);
|
|
136
|
+
s /= MAX_PERCENTAGE;
|
|
137
|
+
l /= MAX_PERCENTAGE;
|
|
138
|
+
const brightness = l + s * Math.min(l, 1 - l);
|
|
139
|
+
const saturation = brightness === 0 ? 0 : 2 * (1 - l / brightness);
|
|
140
|
+
return [
|
|
141
|
+
roundNum(h),
|
|
142
|
+
roundNum(saturation * MAX_PERCENTAGE),
|
|
143
|
+
roundNum(brightness * MAX_PERCENTAGE),
|
|
144
|
+
roundTo2Decimals(a),
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
function hsbaToRgba(h, s, b, a = 1) {
|
|
148
|
+
validateHsb(h, s, b);
|
|
149
|
+
validateAlpha(a);
|
|
150
|
+
s /= MAX_PERCENTAGE;
|
|
151
|
+
b /= MAX_PERCENTAGE;
|
|
152
|
+
const k = (n) => (n + h / 60) % 6;
|
|
153
|
+
const f = (n) => b * (1 - s * Math.max(0, Math.min(k(n), 4 - k(n), 1)));
|
|
154
|
+
return [
|
|
155
|
+
roundNum(f(5) * MAX_RGB),
|
|
156
|
+
roundNum(f(3) * MAX_RGB),
|
|
157
|
+
roundNum(f(1) * MAX_RGB),
|
|
158
|
+
roundTo2Decimals(a),
|
|
159
|
+
];
|
|
160
|
+
}
|
|
161
|
+
function rgbToHsba(r, g, b, a = 1) {
|
|
162
|
+
const { h, s, b: br, a: alpha } = rgbaToHsb(r, g, b, a);
|
|
163
|
+
return [h, s, br, alpha];
|
|
164
|
+
}
|
|
165
|
+
function hsbaToHex(h, s, b, a = 1) {
|
|
166
|
+
const [r, g, b_, a_] = hsbaToRgba(h, s, b, a);
|
|
167
|
+
return rgbToHex(r, g, b_, a_);
|
|
168
|
+
}
|
|
169
|
+
function rgbToHex(r, g, b, a = 1) {
|
|
170
|
+
validateRgb(r, g, b);
|
|
171
|
+
validateAlpha(a);
|
|
172
|
+
let rgba = [r, g, b];
|
|
173
|
+
if (a < 1) {
|
|
174
|
+
rgba.push(Math.round(a * 255));
|
|
175
|
+
}
|
|
176
|
+
return ('#' +
|
|
177
|
+
rgba
|
|
178
|
+
.map(x => Math.round(x).toString(16).padStart(2, '0'))
|
|
179
|
+
.join('')
|
|
180
|
+
.toUpperCase());
|
|
181
|
+
}
|
|
182
|
+
function validateRgb(r, g, b) {
|
|
183
|
+
if (r < 0 || r > MAX_RGB || g < 0 || g > MAX_RGB || b < 0 || b > MAX_RGB) {
|
|
184
|
+
throw new Error('Invalid RGB values');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function validateRgba(r, g, b, a) {
|
|
188
|
+
validateRgb(r, g, b);
|
|
189
|
+
validateAlpha(a);
|
|
190
|
+
}
|
|
191
|
+
function validateHsb(h, s, b) {
|
|
192
|
+
if (h < 0 || h > MAX_HUE || s < 0 || s > MAX_PERCENTAGE || b < 0 || b > MAX_PERCENTAGE) {
|
|
193
|
+
throw new Error('Invalid HSB values');
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function validateHsl(h, s, l) {
|
|
197
|
+
if (h < 0 || h >= MAX_HUE || s < 0 || s > MAX_PERCENTAGE || l < 0 || l > MAX_PERCENTAGE) {
|
|
198
|
+
throw new Error('Invalid HSL values');
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function validateAlpha(a) {
|
|
202
|
+
if (a < 0 || a > 1) {
|
|
203
|
+
throw new Error('Invalid alpha value');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function roundNum(num) {
|
|
207
|
+
return Math.round(num);
|
|
208
|
+
}
|
|
209
|
+
function roundTo2Decimals(num) {
|
|
210
|
+
return Math.round(num * 100) / 100;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
class ColorSpectrum {
|
|
214
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: ColorSpectrum, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
215
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.0.0", type: ColorSpectrum, isStandalone: true, selector: "[ngbColorSpectrum]", host: { styleAttribute: "background-image: linear-gradient(0deg, rgb(0, 0, 0), transparent), linear-gradient(90deg, rgb(255, 255, 255), rgba(255, 255, 255, 0)); background-color: var(--hue-color);" }, hostDirectives: [{ directive: i1.Drag }], ngImport: i0 }); }
|
|
216
|
+
}
|
|
217
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: ColorSpectrum, decorators: [{
|
|
218
|
+
type: Directive,
|
|
219
|
+
args: [{
|
|
220
|
+
selector: '[ngbColorSpectrum]',
|
|
221
|
+
hostDirectives: [Drag],
|
|
222
|
+
host: {
|
|
223
|
+
style: 'background-image: linear-gradient(0deg, rgb(0, 0, 0), transparent), linear-gradient(90deg, rgb(255, 255, 255), rgba(255, 255, 255, 0)); background-color: var(--hue-color);',
|
|
224
|
+
},
|
|
225
|
+
}]
|
|
226
|
+
}] });
|
|
227
|
+
class ColorSpectrumSelector {
|
|
228
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: ColorSpectrumSelector, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
229
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.0.0", type: ColorSpectrumSelector, isStandalone: true, selector: "[ngbColorSpectrumSelector]", host: { attributes: { "type": "button" } }, ngImport: i0 }); }
|
|
230
|
+
}
|
|
231
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: ColorSpectrumSelector, decorators: [{
|
|
232
|
+
type: Directive,
|
|
233
|
+
args: [{
|
|
234
|
+
selector: '[ngbColorSpectrumSelector]',
|
|
235
|
+
host: {
|
|
236
|
+
type: 'button',
|
|
237
|
+
},
|
|
238
|
+
}]
|
|
239
|
+
}] });
|
|
240
|
+
class ColorSelected {
|
|
241
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: ColorSelected, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
242
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.0.0", type: ColorSelected, isStandalone: true, selector: "[ngbColorSelected]", ngImport: i0 }); }
|
|
243
|
+
}
|
|
244
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: ColorSelected, decorators: [{
|
|
245
|
+
type: Directive,
|
|
246
|
+
args: [{ selector: '[ngbColorSelected]' }]
|
|
247
|
+
}] });
|
|
248
|
+
class ColorHue {
|
|
249
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: ColorHue, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
250
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.0.0", type: ColorHue, isStandalone: true, selector: "[ngbColorHue]", host: { styleAttribute: "inset: 0px; background: linear-gradient(to right, rgb(255, 0, 0), rgb(255, 255, 0), rgb(0, 255, 0), rgb(0, 255, 255), rgb(0, 0, 255), rgb(255, 0, 255), rgb(255, 0, 0));" }, hostDirectives: [{ directive: i1.Drag }], ngImport: i0 }); }
|
|
251
|
+
}
|
|
252
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: ColorHue, decorators: [{
|
|
253
|
+
type: Directive,
|
|
254
|
+
args: [{
|
|
255
|
+
selector: '[ngbColorHue]',
|
|
256
|
+
hostDirectives: [Drag],
|
|
257
|
+
host: {
|
|
258
|
+
style: 'inset: 0px; background: linear-gradient(to right, rgb(255, 0, 0), rgb(255, 255, 0), rgb(0, 255, 0), rgb(0, 255, 255), rgb(0, 0, 255), rgb(255, 0, 255), rgb(255, 0, 0));',
|
|
259
|
+
},
|
|
260
|
+
}]
|
|
261
|
+
}] });
|
|
262
|
+
class ColorHueThumb {
|
|
263
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: ColorHueThumb, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
264
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.0.0", type: ColorHueThumb, isStandalone: true, selector: "[ngbColorHueThumb]", host: { attributes: { "type": "button" } }, ngImport: i0 }); }
|
|
265
|
+
}
|
|
266
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: ColorHueThumb, decorators: [{
|
|
267
|
+
type: Directive,
|
|
268
|
+
args: [{
|
|
269
|
+
selector: '[ngbColorHueThumb]',
|
|
270
|
+
host: {
|
|
271
|
+
type: 'button',
|
|
272
|
+
},
|
|
273
|
+
}]
|
|
274
|
+
}] });
|
|
275
|
+
class ColorAlpha {
|
|
276
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: ColorAlpha, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
277
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.0", type: ColorAlpha, isStandalone: true, selector: "[ngbColorAlpha]", host: { styleAttribute: "\n background-image: conic-gradient(\n rgba(0, 0, 0, 0.06) 0 25%,\n transparent 0 50%,\n rgba(0, 0, 0, 0.06) 0 75%,\n transparent 0\n );\n background-size: 8px 8px;\n " }, hostDirectives: [{ directive: i1.Drag }], ngImport: i0, template: ` <div
|
|
278
|
+
style="height: 100%; inset: 0px; background: linear-gradient(to right, rgba(255, 0, 4, 0), var(--hue-color));"
|
|
279
|
+
>
|
|
280
|
+
<ng-content />
|
|
281
|
+
</div>`, isInline: true }); }
|
|
282
|
+
}
|
|
283
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: ColorAlpha, decorators: [{
|
|
284
|
+
type: Component,
|
|
285
|
+
args: [{
|
|
286
|
+
selector: '[ngbColorAlpha]',
|
|
287
|
+
hostDirectives: [Drag],
|
|
288
|
+
template: ` <div
|
|
289
|
+
style="height: 100%; inset: 0px; background: linear-gradient(to right, rgba(255, 0, 4, 0), var(--hue-color));"
|
|
290
|
+
>
|
|
291
|
+
<ng-content />
|
|
292
|
+
</div>`,
|
|
293
|
+
host: {
|
|
294
|
+
style: `
|
|
295
|
+
background-image: conic-gradient(
|
|
296
|
+
rgba(0, 0, 0, 0.06) 0 25%,
|
|
297
|
+
transparent 0 50%,
|
|
298
|
+
rgba(0, 0, 0, 0.06) 0 75%,
|
|
299
|
+
transparent 0
|
|
300
|
+
);
|
|
301
|
+
background-size: 8px 8px;
|
|
302
|
+
`,
|
|
303
|
+
},
|
|
304
|
+
}]
|
|
305
|
+
}] });
|
|
306
|
+
class ColorAlphaThumb {
|
|
307
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: ColorAlphaThumb, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
308
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.0.0", type: ColorAlphaThumb, isStandalone: true, selector: "[ngbColorAlphaThumb]", host: { attributes: { "type": "button" } }, ngImport: i0 }); }
|
|
309
|
+
}
|
|
310
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: ColorAlphaThumb, decorators: [{
|
|
311
|
+
type: Directive,
|
|
312
|
+
args: [{
|
|
313
|
+
selector: '[ngbColorAlphaThumb]',
|
|
314
|
+
host: {
|
|
315
|
+
type: 'button',
|
|
316
|
+
},
|
|
317
|
+
}]
|
|
318
|
+
}] });
|
|
319
|
+
class NgbColorPicker {
|
|
320
|
+
constructor() {
|
|
321
|
+
this.el = inject(ElementRef);
|
|
322
|
+
this.dialogRef = inject(DialogRef, { optional: true });
|
|
323
|
+
this.hueDiv = viewChild.required(ColorHue, { read: Drag });
|
|
324
|
+
this.hueSelector = viewChild.required(ColorHueThumb, { read: ElementRef });
|
|
325
|
+
this.spectrumDiv = viewChild.required(ColorSpectrum, {
|
|
326
|
+
read: Drag,
|
|
327
|
+
});
|
|
328
|
+
this.spectrumSelector = viewChild.required(ColorSpectrumSelector, { read: ElementRef });
|
|
329
|
+
this.selectedColor = viewChild.required(ColorSelected, { read: ElementRef });
|
|
330
|
+
this.alpha = 100; // 0-100
|
|
331
|
+
this.alphaDiv = viewChild.required(ColorAlpha, { read: Drag });
|
|
332
|
+
this.alphaSelector = viewChild.required(ColorAlphaThumb, { read: ElementRef });
|
|
333
|
+
this.valueChange = output();
|
|
334
|
+
this.format = input(this.dialogRef?.data.format || 'hex');
|
|
335
|
+
this.presetColors = input(this.dialogRef?.data.presetColors || []);
|
|
336
|
+
this.hue = 0;
|
|
337
|
+
this.saturation = 0;
|
|
338
|
+
this.brightness = 0;
|
|
339
|
+
this.localValue = '';
|
|
340
|
+
this.colorParsers = new Map([
|
|
341
|
+
['hsb', parseHsba],
|
|
342
|
+
['hex', hexToHsb],
|
|
343
|
+
['rgb', (value) => rgbToHsba(...parseRgba(value))],
|
|
344
|
+
['hsl', (value) => hslaToHsba(...parseHsba(value))],
|
|
345
|
+
]);
|
|
346
|
+
afterNextRender(() => {
|
|
347
|
+
this.setupEventListeners();
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
calculateCoordinates(e, el) {
|
|
351
|
+
const rect = el.nativeElement.getBoundingClientRect();
|
|
352
|
+
let x = Math.round(e.clientX - rect.left);
|
|
353
|
+
let y = Math.round(e.clientY - rect.top);
|
|
354
|
+
// Constrain x and y within the bounds of the spectrum box
|
|
355
|
+
x = Math.max(0, Math.min(x, rect.width));
|
|
356
|
+
y = Math.max(0, Math.min(y, rect.height));
|
|
357
|
+
return { x, y, rect };
|
|
358
|
+
}
|
|
359
|
+
setupEventListeners() {
|
|
360
|
+
this.setupDragListener(this.hueDiv(), (x, y, w, h) => this.updateHue(x, 0, w, h));
|
|
361
|
+
this.setupDragListener(this.spectrumDiv(), this.updateSpectrum.bind(this));
|
|
362
|
+
this.setupDragListener(this.alphaDiv(), (x, y, w) => this.updateAlpha(x, 0, w));
|
|
363
|
+
}
|
|
364
|
+
setupDragListener(dragElement, updateFunction) {
|
|
365
|
+
dragElement.events.subscribe(event => {
|
|
366
|
+
if (event.type === 'start' || event.type === 'move') {
|
|
367
|
+
this.handleColorEvent(event.event, dragElement.el, updateFunction);
|
|
368
|
+
// If we want to avoid emitting the value on every move,
|
|
369
|
+
// we can add a flag to emit only when the event is 'end'
|
|
370
|
+
this.valueChange.emit(this.localValue);
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
handleColorEvent(event, element, updateFunction) {
|
|
375
|
+
const { x, y, rect } = this.calculateCoordinates(event, element);
|
|
376
|
+
updateFunction(x, y, rect.width, rect.height);
|
|
377
|
+
this.updateValue();
|
|
378
|
+
}
|
|
379
|
+
updateHue(x, y, width, height) {
|
|
380
|
+
this.hue = Math.round((x / width) * 360);
|
|
381
|
+
this.el.nativeElement.style.setProperty('--hue-color', `hsl(${this.hue}, 100%, 50%)`);
|
|
382
|
+
const hueSelector = this.hueSelector().nativeElement;
|
|
383
|
+
hueSelector.style.left = `${x}px`;
|
|
384
|
+
if (this.lastSpectrumEvent)
|
|
385
|
+
this.updateValue();
|
|
386
|
+
}
|
|
387
|
+
updateSpectrum(x, y, width, height) {
|
|
388
|
+
const { s, b } = this.calculateSaturationAndLuminous(x, y, width, height);
|
|
389
|
+
this.saturation = s;
|
|
390
|
+
this.brightness = b;
|
|
391
|
+
this.lastSpectrumEvent = { clientX: x, clientY: y };
|
|
392
|
+
const spectrumSelector = this.spectrumSelector().nativeElement;
|
|
393
|
+
spectrumSelector.style.left = `${x - spectrumSelector.offsetWidth / 2}px`;
|
|
394
|
+
spectrumSelector.style.top = `${y - spectrumSelector.offsetHeight / 2}px`;
|
|
395
|
+
}
|
|
396
|
+
updateAlpha(x, y, width) {
|
|
397
|
+
this.alpha = Math.round((x / width) * 100);
|
|
398
|
+
const alphaSelector = this.alphaSelector().nativeElement;
|
|
399
|
+
alphaSelector.style.left = `${x}px`;
|
|
400
|
+
}
|
|
401
|
+
setValue(value, emit = false) {
|
|
402
|
+
if (!value)
|
|
403
|
+
return;
|
|
404
|
+
this.parse(value);
|
|
405
|
+
this.updateValue(emit);
|
|
406
|
+
this.el.nativeElement.style.setProperty('--hue-color', this.getColor(this.hue, 100, 100, 100));
|
|
407
|
+
this.updateSelectorPositions();
|
|
408
|
+
}
|
|
409
|
+
updateSelectorPositions() {
|
|
410
|
+
this.updateSelectorPosition(this.hueDiv().el, this.hueSelector(), this.hue / 360);
|
|
411
|
+
this.updateSelectorPosition(this.alphaDiv().el, this.alphaSelector(), this.alpha / 100);
|
|
412
|
+
this.updateSpectrumSelectorPosition();
|
|
413
|
+
}
|
|
414
|
+
updateSelectorPosition(containerEl, selectorEl, ratio) {
|
|
415
|
+
selectorEl.nativeElement.style.left = ratio * containerEl.nativeElement.clientWidth + 'px';
|
|
416
|
+
}
|
|
417
|
+
updateSpectrumSelectorPosition() {
|
|
418
|
+
const spectrumRect = this.spectrumDiv().el.nativeElement.getBoundingClientRect();
|
|
419
|
+
const spectrumSelector = this.spectrumSelector().nativeElement;
|
|
420
|
+
const { x, y } = this.calculateSpectrumPosition(this.saturation, this.brightness, spectrumRect.width, spectrumRect.height);
|
|
421
|
+
spectrumSelector.style.left = `${x}px`;
|
|
422
|
+
spectrumSelector.style.top = `${y}px`;
|
|
423
|
+
}
|
|
424
|
+
// Simplified function to calculate the x and y based on the saturation and lightness
|
|
425
|
+
calculateSpectrumPosition(s, l, spectrumWidth, spectrumHeight) {
|
|
426
|
+
const handlerSize = 16;
|
|
427
|
+
const half = handlerSize / 2;
|
|
428
|
+
const x = (spectrumWidth * s) / 100 - half;
|
|
429
|
+
const y = (spectrumHeight * (100 - l)) / 100 - half;
|
|
430
|
+
return { x, y };
|
|
431
|
+
}
|
|
432
|
+
calculateSaturationAndLuminous(x, y, sw, sh) {
|
|
433
|
+
const s = Math.round((x / sw) * 100);
|
|
434
|
+
const b = Math.round(100 - (y / sh) * 100);
|
|
435
|
+
return { s, b };
|
|
436
|
+
}
|
|
437
|
+
updateValue(emit = false) {
|
|
438
|
+
this.localValue = this.toString();
|
|
439
|
+
const hsla = this.getColor(this.hue, this.saturation, this.brightness, this.alpha);
|
|
440
|
+
this.el.nativeElement.style.setProperty('--spectrum-color', hsla);
|
|
441
|
+
this.selectedColor().nativeElement.style.backgroundColor = hsla;
|
|
442
|
+
this.spectrumSelector().nativeElement.style.backgroundColor = hsla;
|
|
443
|
+
if (emit)
|
|
444
|
+
this.valueChange.emit(this.localValue);
|
|
445
|
+
}
|
|
446
|
+
getColor(h, s, b, a) {
|
|
447
|
+
const [hh, ss, l] = hsbToHsl(h, s, b);
|
|
448
|
+
return `hsla(${hh}, ${ss}%, ${l}%, ${a / 100})`;
|
|
449
|
+
}
|
|
450
|
+
parse(value) {
|
|
451
|
+
const parser = this.colorParsers.get(this.format());
|
|
452
|
+
if (parser) {
|
|
453
|
+
[this.hue, this.saturation, this.brightness, this.alpha] = parser(value);
|
|
454
|
+
this.alpha = Math.round(this.alpha * 100);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
toString() {
|
|
458
|
+
const alpha = this.alpha / 100;
|
|
459
|
+
const formatters = {
|
|
460
|
+
hsb: () => `hsba(${this.hue}, ${this.saturation}%, ${this.brightness}%, ${alpha})`,
|
|
461
|
+
hex: () => hsbaToHex(this.hue, this.saturation, this.brightness, alpha),
|
|
462
|
+
rgb: () => {
|
|
463
|
+
const [r, g, b, a] = hsbaToRgba(this.hue, this.saturation, this.brightness, alpha);
|
|
464
|
+
return a === 1 ? `rgb(${r}, ${g}, ${b})` : `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
465
|
+
},
|
|
466
|
+
hsl: () => {
|
|
467
|
+
const [h, s, l] = hsbToHsl(this.hue, this.saturation, this.brightness);
|
|
468
|
+
return `hsla(${h}, ${s}%, ${l}%, ${alpha})`;
|
|
469
|
+
},
|
|
470
|
+
};
|
|
471
|
+
return formatters[this.format()]?.() || '';
|
|
472
|
+
}
|
|
473
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NgbColorPicker, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
474
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "19.0.0", type: NgbColorPicker, isStandalone: true, selector: "ngb-color-picker-container", inputs: { format: { classPropertyName: "format", publicName: "format", isSignal: true, isRequired: false, transformFunction: null }, presetColors: { classPropertyName: "presetColors", publicName: "presetColors", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { valueChange: "valueChange" }, host: { styleAttribute: "\n --hue-color: rgb(255, 0, 0);\n --spectrum-color: rgb(0, 0, 0);\n " }, viewQueries: [{ propertyName: "hueDiv", first: true, predicate: ColorHue, descendants: true, read: Drag, isSignal: true }, { propertyName: "hueSelector", first: true, predicate: ColorHueThumb, descendants: true, read: ElementRef, isSignal: true }, { propertyName: "spectrumDiv", first: true, predicate: ColorSpectrum, descendants: true, read: Drag, isSignal: true }, { propertyName: "spectrumSelector", first: true, predicate: ColorSpectrumSelector, descendants: true, read: ElementRef, isSignal: true }, { propertyName: "selectedColor", first: true, predicate: ColorSelected, descendants: true, read: ElementRef, isSignal: true }, { propertyName: "alphaDiv", first: true, predicate: ColorAlpha, descendants: true, read: Drag, isSignal: true }, { propertyName: "alphaSelector", first: true, predicate: ColorAlphaThumb, descendants: true, read: ElementRef, isSignal: true }], ngImport: i0 }); }
|
|
475
|
+
}
|
|
476
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NgbColorPicker, decorators: [{
|
|
477
|
+
type: Directive,
|
|
478
|
+
args: [{
|
|
479
|
+
selector: 'ngb-color-picker-container',
|
|
480
|
+
host: {
|
|
481
|
+
style: `
|
|
482
|
+
--hue-color: rgb(255, 0, 0);
|
|
483
|
+
--spectrum-color: rgb(0, 0, 0);
|
|
484
|
+
`,
|
|
485
|
+
},
|
|
486
|
+
}]
|
|
487
|
+
}], ctorParameters: () => [] });
|
|
488
|
+
|
|
489
|
+
const ColorPicker = new InjectionToken('ColorPicker');
|
|
490
|
+
const registerColorPicker = ({ picker, accessor }) => [
|
|
491
|
+
{ provide: ColorPicker, useValue: picker },
|
|
492
|
+
provideValueAccessor(accessor),
|
|
493
|
+
];
|
|
494
|
+
class ColorPickerTrigger {
|
|
495
|
+
constructor() {
|
|
496
|
+
this.el = inject(ElementRef);
|
|
497
|
+
this.colorPicker = inject(ColorPicker, { optional: true }) ?? NgbColorPicker;
|
|
498
|
+
this.popover = ngbPopoverPortal();
|
|
499
|
+
this.injector = inject(Injector);
|
|
500
|
+
this.format = input('hex');
|
|
501
|
+
this.presetColors = input();
|
|
502
|
+
this.value = model();
|
|
503
|
+
}
|
|
504
|
+
open() {
|
|
505
|
+
const { childSignal } = this.popover.open(this.colorPicker, {
|
|
506
|
+
target: this.el.nativeElement,
|
|
507
|
+
position: 'bl',
|
|
508
|
+
offset: 0,
|
|
509
|
+
data: { format: this.format(), presetColors: this.presetColors() },
|
|
510
|
+
width: '255px',
|
|
511
|
+
});
|
|
512
|
+
this.effectRef?.destroy();
|
|
513
|
+
this.effectRef = effect(() => {
|
|
514
|
+
const colorPicker = childSignal()?.instance;
|
|
515
|
+
if (colorPicker) {
|
|
516
|
+
untracked(() => {
|
|
517
|
+
colorPicker.setValue(this.value() || '#000000');
|
|
518
|
+
colorPicker.valueChange.subscribe(res => {
|
|
519
|
+
this.value.set(res);
|
|
520
|
+
});
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
}, { injector: this.injector });
|
|
524
|
+
}
|
|
525
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: ColorPickerTrigger, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
526
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.0.0", type: ColorPickerTrigger, isStandalone: true, selector: "[ngbColorPickerTrigger]", inputs: { format: { classPropertyName: "format", publicName: "format", isSignal: true, isRequired: false, transformFunction: null }, presetColors: { classPropertyName: "presetColors", publicName: "presetColors", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { value: "valueChange" }, host: { listeners: { "click": "open()" } }, ngImport: i0 }); }
|
|
527
|
+
}
|
|
528
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: ColorPickerTrigger, decorators: [{
|
|
529
|
+
type: Directive,
|
|
530
|
+
args: [{
|
|
531
|
+
selector: '[ngbColorPickerTrigger]',
|
|
532
|
+
host: {
|
|
533
|
+
'(click)': 'open()',
|
|
534
|
+
},
|
|
535
|
+
}]
|
|
536
|
+
}] });
|
|
537
|
+
|
|
538
|
+
class NgbColorInput {
|
|
539
|
+
constructor() {
|
|
540
|
+
this.format = input('hex');
|
|
541
|
+
this.presetColors = input();
|
|
542
|
+
this.value = model('');
|
|
543
|
+
this.onChange = (_) => { };
|
|
544
|
+
this.onTouched = () => { };
|
|
545
|
+
}
|
|
546
|
+
updateValue(value = '') {
|
|
547
|
+
this.value.set(value);
|
|
548
|
+
this.onChange(value);
|
|
549
|
+
this.onTouched();
|
|
550
|
+
}
|
|
551
|
+
writeValue(value) {
|
|
552
|
+
this.value.set(value);
|
|
553
|
+
}
|
|
554
|
+
registerOnChange(fn) {
|
|
555
|
+
this.onChange = fn;
|
|
556
|
+
}
|
|
557
|
+
registerOnTouched(fn) {
|
|
558
|
+
this.onTouched = fn;
|
|
559
|
+
}
|
|
560
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NgbColorInput, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
561
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.0.0", type: NgbColorInput, isStandalone: true, selector: "[ngbColorInput]", inputs: { format: { classPropertyName: "format", publicName: "format", isSignal: true, isRequired: false, transformFunction: null }, presetColors: { classPropertyName: "presetColors", publicName: "presetColors", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { value: "valueChange" }, providers: [provideValueAccessor(NgbColorInput)], ngImport: i0 }); }
|
|
562
|
+
}
|
|
563
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NgbColorInput, decorators: [{
|
|
564
|
+
type: Directive,
|
|
565
|
+
args: [{
|
|
566
|
+
selector: '[ngbColorInput]',
|
|
567
|
+
providers: [provideValueAccessor(NgbColorInput)],
|
|
568
|
+
}]
|
|
569
|
+
}] });
|
|
570
|
+
|
|
571
|
+
/*
|
|
572
|
+
* Public API Surface of color-picker
|
|
573
|
+
*/
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Generated bundle index. Do not edit.
|
|
577
|
+
*/
|
|
578
|
+
|
|
579
|
+
export { ColorAlpha, ColorAlphaThumb, ColorHue, ColorHueThumb, ColorPickerTrigger, ColorSelected, ColorSpectrum, ColorSpectrumSelector, NgbColorInput, NgbColorPicker, registerColorPicker };
|
|
580
|
+
//# sourceMappingURL=ngbase-adk-color-picker.mjs.map
|