@vonage/vivid 5.2.0 → 5.4.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/accordion-item/definition.cjs +2 -1
- package/accordion-item/definition.js +3 -2
- package/alert/definition.cjs +1 -1
- package/alert/definition.js +2 -2
- package/alert/index.cjs +1 -1
- package/alert/index.js +1 -1
- package/audio-player/definition.cjs +4 -2
- package/audio-player/definition.js +4 -2
- package/audio-player/index.cjs +5 -3
- package/audio-player/index.js +5 -3
- package/badge/definition.js +1 -1
- package/badge/index.cjs +2 -2
- package/badge/index.js +4 -4
- package/banner/definition.js +1 -1
- package/banner/index.cjs +3 -3
- package/banner/index.js +6 -6
- package/breadcrumb-item/index.cjs +1 -1
- package/breadcrumb-item/index.js +1 -1
- package/bundled/affix.cjs +7 -7
- package/bundled/affix.js +5 -5
- package/bundled/anchored.cjs +1 -1
- package/bundled/anchored.js +6 -6
- package/bundled/attribute-binding-behaviour.cjs +1 -1
- package/bundled/attribute-binding-behaviour.js +15 -13
- package/bundled/base-color-picker.cjs +13 -0
- package/bundled/base-color-picker.js +194 -0
- package/bundled/button.cjs +1 -1
- package/bundled/button.js +2 -2
- package/bundled/calendar-picker.template.cjs +7 -7
- package/bundled/calendar-picker.template.js +118 -118
- package/bundled/char-count.cjs +1 -1
- package/bundled/char-count.js +1 -1
- package/bundled/children.cjs +1 -1
- package/bundled/children.js +28 -20
- package/bundled/definition.cjs +3 -3
- package/bundled/definition.js +38 -38
- package/bundled/definition10.cjs +72 -18
- package/bundled/definition10.js +351 -65
- package/bundled/definition11.cjs +19 -10
- package/bundled/definition11.js +217 -36
- package/bundled/definition12.cjs +10 -1
- package/bundled/definition12.js +38 -14
- package/bundled/definition13.cjs +1 -73
- package/bundled/definition13.js +15 -354
- package/bundled/definition15.cjs +1 -1
- package/bundled/definition15.js +1 -1
- package/bundled/definition16.cjs +2 -2
- package/bundled/definition16.js +8 -8
- package/bundled/definition17.cjs +7 -7
- package/bundled/definition17.js +17 -17
- package/bundled/definition19.cjs +23 -24
- package/bundled/definition19.js +151 -163
- package/bundled/definition2.cjs +9 -5
- package/bundled/definition2.js +21 -17
- package/bundled/definition22.cjs +9 -9
- package/bundled/definition22.js +31 -31
- package/bundled/definition3.cjs +1 -1
- package/bundled/definition3.js +1 -1
- package/bundled/definition6.cjs +3 -3
- package/bundled/definition6.js +28 -28
- package/bundled/definition7.cjs +1 -1
- package/bundled/definition7.js +6 -6
- package/bundled/definition8.cjs +2 -2
- package/bundled/definition8.js +4 -4
- package/bundled/definition9.cjs +5 -5
- package/bundled/definition9.js +394 -392
- package/bundled/delegates-aria.cjs +1 -1
- package/bundled/delegates-aria.js +59 -46
- package/bundled/form-associated.cjs +1 -1
- package/bundled/form-associated.js +3 -3
- package/bundled/host-semantics.cjs +1 -1
- package/bundled/host-semantics.js +48 -34
- package/bundled/listbox.cjs +1 -1
- package/bundled/listbox.js +82 -102
- package/bundled/localized.cjs +1 -1
- package/bundled/localized.js +51 -36
- package/bundled/mixins.cjs +18 -18
- package/bundled/mixins.js +99 -93
- package/bundled/normalize.cjs +1 -0
- package/bundled/normalize.js +7 -0
- package/bundled/picker-field.template.cjs +1 -1
- package/bundled/picker-field.template.js +4 -4
- package/bundled/ref.cjs +1 -1
- package/bundled/ref.js +8 -25
- package/bundled/repeat.cjs +1 -1
- package/bundled/repeat.js +459 -233
- package/bundled/slider.template.cjs +1 -1
- package/bundled/slider.template.js +2 -2
- package/bundled/slotted.cjs +1 -1
- package/bundled/slotted.js +62 -45
- package/bundled/time-selection-picker.template.cjs +1 -1
- package/bundled/time-selection-picker.template.js +5 -5
- package/bundled/vivid-element.cjs +5 -1
- package/bundled/vivid-element.js +2159 -1162
- package/bundled/when.cjs +1 -1
- package/bundled/when.js +8 -7
- package/calendar/definition.cjs +1 -1
- package/calendar/definition.js +2 -2
- package/calendar/index.cjs +1 -1
- package/calendar/index.js +15 -15
- package/calendar-event/index.cjs +1 -1
- package/calendar-event/index.js +1 -1
- package/card/definition.cjs +11 -3
- package/card/definition.js +11 -3
- package/card/index.cjs +19 -11
- package/card/index.js +35 -27
- package/color-picker/definition.cjs +1079 -0
- package/color-picker/definition.js +1073 -0
- package/color-picker/index.cjs +127 -0
- package/color-picker/index.js +726 -0
- package/combobox/definition.cjs +8 -28
- package/combobox/definition.js +10 -30
- package/combobox/index.cjs +7 -7
- package/combobox/index.js +60 -74
- package/contextual-help/index.cjs +1 -1
- package/contextual-help/index.js +1 -1
- package/custom-elements.json +1670 -163
- package/data-grid/definition.cjs +862 -27
- package/data-grid/definition.js +863 -28
- package/data-grid/index.cjs +25 -25
- package/data-grid/index.js +175 -168
- package/date-picker/definition.cjs +1 -1
- package/date-picker/definition.js +1 -1
- package/date-picker/index.cjs +1 -1
- package/date-picker/index.js +2 -2
- package/date-range-picker/definition.cjs +1 -1
- package/date-range-picker/definition.js +1 -1
- package/date-range-picker/index.cjs +1 -1
- package/date-range-picker/index.js +2 -2
- package/date-time-picker/definition.cjs +1 -1
- package/date-time-picker/definition.js +1 -1
- package/date-time-picker/index.cjs +1 -1
- package/date-time-picker/index.js +2 -2
- package/dial-pad/definition.cjs +4 -0
- package/dial-pad/definition.js +4 -0
- package/dial-pad/index.cjs +3 -3
- package/dial-pad/index.js +42 -39
- package/dialog/definition.cjs +6 -3
- package/dialog/definition.js +6 -3
- package/dialog/index.cjs +22 -19
- package/dialog/index.js +48 -45
- package/elevation/definition.cjs +1 -1
- package/elevation/definition.js +1 -1
- package/empty-state/definition.cjs +7 -2
- package/empty-state/definition.js +7 -2
- package/empty-state/index.cjs +10 -5
- package/empty-state/index.js +18 -13
- package/fab/definition.js +1 -1
- package/fab/index.cjs +2 -2
- package/fab/index.js +4 -4
- package/file-picker/definition.cjs +2 -2
- package/file-picker/definition.js +3 -3
- package/file-picker/index.cjs +1 -1
- package/file-picker/index.js +4 -4
- package/header/definition.cjs +1 -1
- package/header/definition.js +1 -1
- package/icon/definition.cjs +10 -6
- package/icon/definition.js +10 -6
- package/index.cjs +7 -4
- package/index.js +3 -3
- package/lib/accordion/accordion.d.ts +1 -1
- package/lib/accordion/definition.d.ts +1 -1
- package/lib/accordion-item/accordion-item.d.ts +2 -2
- package/lib/action-group/action-group.d.ts +2 -2
- package/lib/alert/alert.d.ts +4 -4
- package/lib/audio-player/audio-player.d.ts +3 -3
- package/lib/avatar/avatar.d.ts +2 -2
- package/lib/badge/badge.d.ts +2 -2
- package/lib/banner/banner.d.ts +6 -6
- package/lib/breadcrumb/breadcrumb.d.ts +2 -2
- package/lib/breadcrumb-item/breadcrumb-item.d.ts +2 -2
- package/lib/button/button.d.ts +6 -6
- package/lib/button/button.template.d.ts +2 -1
- package/lib/calendar/calendar.d.ts +1 -1
- package/lib/calendar-event/calendar-event.d.ts +2 -2
- package/lib/card/card.d.ts +2 -2
- package/lib/checkbox/checkbox.d.ts +12 -12
- package/lib/color-picker/color-picker.d.ts +2420 -0
- package/lib/color-picker/color-picker.template.d.ts +3 -0
- package/lib/color-picker/definition.d.ts +4 -0
- package/lib/color-picker/locale.d.ts +9 -0
- package/lib/combobox/combobox.d.ts +15 -14
- package/lib/combobox/combobox.options.d.ts +1 -1
- package/lib/components.d.ts +1 -0
- package/lib/data-grid/data-grid-cell.d.ts +4 -4
- package/lib/data-grid/data-grid-row.d.ts +3 -4
- package/lib/data-grid/data-grid.d.ts +1 -2
- package/lib/date-picker/date-picker.d.ts +54 -54
- package/lib/date-range-picker/date-range-picker.d.ts +28 -28
- package/lib/date-time-picker/date-time-picker.d.ts +56 -56
- package/lib/dial-pad/dial-pad.d.ts +3 -2
- package/lib/dialog/dialog.d.ts +4 -4
- package/lib/divider/divider.d.ts +3 -3
- package/lib/fab/fab.d.ts +2 -2
- package/lib/file-picker/file-picker.d.ts +14 -14
- package/lib/header/header.d.ts +2 -2
- package/lib/menu/menu.d.ts +4 -4
- package/lib/menu-item/menu-item-role.d.ts +1 -1
- package/lib/menu-item/menu-item.d.ts +4 -4
- package/lib/nav/nav.d.ts +2 -2
- package/lib/nav-disclosure/nav-disclosure.d.ts +4 -4
- package/lib/nav-item/nav-item.d.ts +4 -4
- package/lib/note/note.d.ts +2 -2
- package/lib/number-field/number-field.d.ts +18 -18
- package/lib/option/option.d.ts +4 -4
- package/lib/pagination/pagination.d.ts +2 -2
- package/lib/popup/popup.d.ts +1 -1
- package/lib/progress/progress.d.ts +2 -2
- package/lib/progress-ring/progress-ring.d.ts +2 -2
- package/lib/radio/radio.d.ts +6 -6
- package/lib/radio-group/radio-group.d.ts +2 -2
- package/lib/range-slider/range-slider.d.ts +6 -6
- package/lib/rich-text-editor/menubar/menubar.d.ts +2 -2
- package/lib/rich-text-editor/rich-text-editor.d.ts +2 -2
- package/lib/searchable-select/locale.d.ts +4 -0
- package/lib/searchable-select/option-tag.d.ts +2 -2
- package/lib/searchable-select/searchable-select.d.ts +21 -18
- package/lib/select/select.d.ts +19 -17
- package/lib/selectable-box/selectable-box.d.ts +2 -2
- package/lib/simple-color-picker/locale.d.ts +0 -1
- package/lib/simple-color-picker/simple-color-picker.d.ts +47 -821
- package/lib/slider/slider.d.ts +7 -7
- package/lib/split-button/split-button.d.ts +6 -6
- package/lib/switch/switch.d.ts +4 -4
- package/lib/tab/tab.d.ts +6 -6
- package/lib/tab-panel/tab-panel.d.ts +2 -2
- package/lib/tabs/tabs.d.ts +2 -2
- package/lib/tag/tag.d.ts +6 -6
- package/lib/tag-group/tag-group.d.ts +2 -2
- package/lib/tag-name-map.d.ts +2 -1
- package/lib/text-area/text-area.d.ts +17 -17
- package/lib/text-field/text-field.d.ts +19 -19
- package/lib/time-picker/time-picker.d.ts +28 -28
- package/lib/toggletip/toggletip.d.ts +4 -4
- package/lib/tooltip/tooltip.d.ts +2 -2
- package/lib/tree-item/tree-item.d.ts +4 -4
- package/lib/tree-view/tree-view.d.ts +2 -2
- package/lib/video-player/video-player.d.ts +2 -2
- package/locales/de-DE.cjs +17 -2
- package/locales/de-DE.js +17 -2
- package/locales/en-GB.cjs +17 -2
- package/locales/en-GB.js +17 -2
- package/locales/en-US.cjs +17 -2
- package/locales/en-US.js +17 -2
- package/locales/ja-JP.cjs +17 -2
- package/locales/ja-JP.js +17 -2
- package/locales/zh-CN.cjs +17 -2
- package/locales/zh-CN.js +17 -2
- package/menu/definition.cjs +6 -6
- package/menu/definition.js +7 -7
- package/nav-disclosure/definition.js +1 -1
- package/nav-item/definition.js +1 -1
- package/note/definition.js +1 -1
- package/note/index.cjs +2 -2
- package/note/index.js +4 -4
- package/number-field/definition.cjs +1 -1
- package/number-field/definition.js +3 -3
- package/number-field/index.cjs +5 -5
- package/number-field/index.js +21 -21
- package/option/definition.cjs +6 -77
- package/option/definition.js +3 -78
- package/option/index.cjs +1 -1
- package/option/index.js +1 -1
- package/package.json +34 -8
- package/pagination/definition.cjs +2 -1
- package/pagination/definition.js +2 -1
- package/pagination/index.cjs +12 -12
- package/pagination/index.js +59 -59
- package/popup/definition.cjs +2 -2
- package/popup/definition.js +2 -2
- package/progress/index.cjs +1 -1
- package/progress/index.js +1 -1
- package/radio/definition.cjs +9 -9
- package/radio/definition.js +10 -10
- package/radio-group/definition.cjs +2 -1
- package/radio-group/definition.js +2 -1
- package/radio-group/index.cjs +5 -5
- package/radio-group/index.js +80 -77
- package/range-slider/definition.cjs +1 -1
- package/range-slider/definition.js +1 -1
- package/range-slider/index.cjs +1 -1
- package/range-slider/index.js +1 -1
- package/rich-text-editor/definition.cjs +3 -4
- package/rich-text-editor/definition.js +3 -4
- package/rich-text-editor/index.cjs +27 -27
- package/rich-text-editor/index.js +1208 -1198
- package/searchable-select/definition.cjs +106 -14
- package/searchable-select/definition.js +107 -15
- package/searchable-select/index.cjs +81 -69
- package/searchable-select/index.js +362 -276
- package/select/definition.cjs +25 -42
- package/select/definition.js +26 -43
- package/selectable-box/definition.cjs +1 -1
- package/selectable-box/definition.js +1 -1
- package/selectable-box/index.cjs +3 -3
- package/selectable-box/index.js +20 -20
- package/shared/aria/aria-change-subscription.d.ts +0 -1
- package/shared/aria/aria-mixin.d.ts +3 -3
- package/shared/aria/delegate-aria-behavior.d.ts +5 -10
- package/shared/aria/delegates-aria.d.ts +3 -3
- package/shared/aria/host-semantics-behavior.d.ts +5 -8
- package/shared/aria/host-semantics.d.ts +3 -3
- package/shared/color-picker/base-color-picker.d.ts +436 -0
- package/shared/color-picker/index.d.ts +1 -0
- package/shared/color-picker/locale.d.ts +3 -0
- package/shared/color-picker/utils.d.ts +1 -0
- package/shared/deprecation/replaced-props.d.ts +317 -2
- package/shared/design-system/defineVividComponent.d.ts +2 -2
- package/shared/feedback/feedback-message.d.ts +2 -2
- package/shared/feedback/mixins.d.ts +4 -4
- package/shared/foundation/button/button.d.ts +4 -4
- package/shared/foundation/form-associated/form-associated.d.ts +4 -4
- package/shared/foundation/listbox/listbox.d.ts +4 -0
- package/shared/foundation/vivid-element/vivid-element.d.ts +335 -8
- package/shared/localization/Locale.d.ts +4 -0
- package/shared/patterns/affix.d.ts +4 -4
- package/shared/patterns/anchored.d.ts +4 -4
- package/shared/patterns/char-count/char-count.d.ts +2 -2
- package/shared/patterns/form-elements/form-element.d.ts +4 -4
- package/shared/patterns/form-elements/with-contextual-help.d.ts +6 -6
- package/shared/patterns/form-elements/with-error-text.d.ts +6 -6
- package/shared/patterns/form-elements/with-success-text.d.ts +2 -2
- package/shared/patterns/linkable.d.ts +2 -2
- package/shared/patterns/localized.d.ts +2 -2
- package/shared/patterns/trapped-focus.d.ts +2 -2
- package/shared/picker-field/mixins/calendar-picker.d.ts +14 -14
- package/shared/picker-field/mixins/calendar-picker.template.d.ts +14 -14
- package/shared/picker-field/mixins/inline-time-picker/inline-time-picker.d.ts +2 -2
- package/shared/picker-field/mixins/min-max-calendar-picker.d.ts +28 -28
- package/shared/picker-field/mixins/single-date-picker.d.ts +40 -40
- package/shared/picker-field/mixins/single-value-picker.d.ts +12 -12
- package/shared/picker-field/mixins/time-selection-picker.d.ts +29 -29
- package/shared/picker-field/mixins/time-selection-picker.template.d.ts +28 -28
- package/shared/picker-field/picker-field.d.ts +14 -14
- package/shared/templating/attribute-binding-behaviour.d.ts +3 -4
- package/shared/templating/render-in-light-dom.d.ts +13 -12
- package/side-drawer/index.cjs +1 -1
- package/side-drawer/index.js +1 -1
- package/simple-color-picker/definition.cjs +29 -216
- package/simple-color-picker/definition.js +30 -217
- package/simple-color-picker/index.cjs +9 -21
- package/simple-color-picker/index.js +71 -185
- package/slider/definition.cjs +1 -1
- package/slider/definition.js +1 -1
- package/split-button/definition.js +1 -1
- package/styles/core/all.css +1 -1
- package/styles/core/theme.css +1 -1
- package/styles/core/typography.css +1 -1
- package/styles/tokens/theme-dark.css +4 -4
- package/styles/tokens/theme-light.css +4 -4
- package/styles/tokens/vivid-2-compat.css +1 -1
- package/switch/index.cjs +2 -2
- package/switch/index.js +4 -4
- package/tab/definition.js +1 -1
- package/tabs/definition.cjs +1 -1
- package/tabs/definition.js +2 -2
- package/tabs/index.cjs +2 -2
- package/tabs/index.js +16 -16
- package/tag/definition.js +1 -1
- package/tag/index.cjs +1 -1
- package/tag/index.js +1 -1
- package/text-area/index.cjs +3 -3
- package/text-area/index.js +8 -8
- package/text-field/definition.cjs +2 -2
- package/text-field/definition.js +4 -4
- package/text-field/index.cjs +1 -1
- package/text-field/index.js +1 -1
- package/time-picker/definition.cjs +1 -1
- package/time-picker/definition.js +1 -1
- package/time-picker/index.cjs +1 -1
- package/time-picker/index.js +2 -2
- package/toggletip/definition.cjs +2 -2
- package/toggletip/definition.js +3 -3
- package/tooltip/definition.cjs +1 -1
- package/tooltip/definition.js +1 -1
- package/tree-item/definition.cjs +1 -1
- package/tree-item/definition.js +1 -1
- package/tree-view/definition.cjs +2 -2
- package/tree-view/definition.js +3 -3
- package/tree-view/index.cjs +2 -2
- package/tree-view/index.js +6 -6
- package/unbundled/_commonjsHelpers.cjs +36 -0
- package/unbundled/_commonjsHelpers.js +32 -0
- package/unbundled/affix.cjs +1 -1
- package/unbundled/affix.js +2 -2
- package/unbundled/attribute-binding-behaviour.cjs +11 -10
- package/unbundled/attribute-binding-behaviour.js +11 -10
- package/unbundled/base-color-picker.cjs +278 -0
- package/unbundled/base-color-picker.js +275 -0
- package/unbundled/button.cjs +1 -1
- package/unbundled/button.js +2 -2
- package/unbundled/calendar-picker.template.cjs +4 -4
- package/unbundled/calendar-picker.template.js +5 -5
- package/unbundled/definition.js +1 -1
- package/unbundled/definition2.cjs +1 -1
- package/unbundled/definition2.js +3 -3
- package/unbundled/definition3.cjs +222 -140
- package/unbundled/definition3.js +220 -138
- package/unbundled/definition4.cjs +145 -235
- package/unbundled/definition4.js +143 -233
- package/unbundled/definition5.cjs +269 -27
- package/unbundled/definition5.js +267 -26
- package/unbundled/definition6.cjs +56 -0
- package/unbundled/definition6.js +52 -0
- package/unbundled/delegates-aria.cjs +67 -33
- package/unbundled/delegates-aria.js +69 -35
- package/unbundled/form-associated.cjs +2 -2
- package/unbundled/form-associated.js +3 -3
- package/unbundled/host-semantics.cjs +47 -22
- package/unbundled/host-semantics.js +48 -23
- package/unbundled/listbox.cjs +41 -63
- package/unbundled/listbox.js +39 -61
- package/unbundled/mixins.cjs +34 -27
- package/unbundled/mixins.js +35 -28
- package/unbundled/picker-field.template.cjs +3 -3
- package/unbundled/picker-field.template.js +4 -4
- package/unbundled/slider.template.cjs +1 -1
- package/unbundled/slider.template.js +1 -1
- package/unbundled/time-selection-picker.template.cjs +4 -4
- package/unbundled/time-selection-picker.template.js +5 -5
- package/unbundled/vivid-element.cjs +22 -15
- package/unbundled/vivid-element.js +23 -15
- package/video-player/definition.cjs +69047 -1
- package/video-player/definition.js +69047 -1
- package/video-player/index.cjs +36 -36
- package/video-player/index.js +1895 -1905
- package/visually-hidden/index.cjs +1 -1
- package/visually-hidden/index.js +1 -1
- package/vivid.api.json +719 -224
- package/bundled/option.cjs +0 -1
- package/bundled/option.js +0 -158
- package/unbundled/option.cjs +0 -217
- package/unbundled/option.js +0 -214
|
@@ -0,0 +1,1073 @@
|
|
|
1
|
+
import { V as VividElement, d as defineVividComponent, c as createRegisterFunction } from '../unbundled/vivid-element.js';
|
|
2
|
+
import { P as Popup, p as popupDefinition } from '../unbundled/definition5.js';
|
|
3
|
+
import { VwcIconElement as Icon, iconDefinition } from '../icon/definition.js';
|
|
4
|
+
import { a as WithFeedback, f as feedbackMessageDefinition } from '../unbundled/mixins.js';
|
|
5
|
+
import { attr, observable, nullableNumberConverter, ref, when, html, slotted, repeat } from '@microsoft/fast-element';
|
|
6
|
+
import { D as DelegatesAria, d as delegateAria } from '../unbundled/delegates-aria.js';
|
|
7
|
+
import { W as WithContextualHelp } from '../unbundled/with-contextual-help.js';
|
|
8
|
+
import { B as BaseColorPicker, i as isValidHexColor } from '../unbundled/base-color-picker.js';
|
|
9
|
+
import { W as WithErrorText } from '../unbundled/with-error-text.js';
|
|
10
|
+
import { W as WithSuccessText } from '../unbundled/with-success-text.js';
|
|
11
|
+
import { classNames } from '@microsoft/fast-web-utilities';
|
|
12
|
+
import { VwcTextFieldElement as TextField, textFieldDefinition } from '../text-field/definition.js';
|
|
13
|
+
import { B as Button, b as buttonDefinition } from '../unbundled/definition.js';
|
|
14
|
+
|
|
15
|
+
const styles = ".palette{display:grid;grid-template-columns:repeat(var(--swatches-per-row, 7),var(--_color-swatch-size, 24px))}.swatch{position:relative;padding:0;border:none;border-radius:4px;background-color:var(--swatch-color);block-size:var(--_color-swatch-size, 24px);color:var(--vvd-color-canvas);cursor:pointer;inline-size:var(--_color-swatch-size, 24px)}.swatch.contrast{color:var(--vvd-color-canvas-text)}.swatch:focus-visible{outline:none;box-shadow:0 0 0 4px color-mix(in srgb,var(--vvd-color-cta-500),transparent 85%),inset 0 0 0 3px var(--focus-stroke-gap-color, currentColor);outline:1px solid var(--focus-stroke-color, var(--vvd-color-cta-500));outline-offset:calc(-1px - var(--focus-inset, 0px));--focus-stroke-gap-color: transparent;--focus-inset: -3px}:host{display:inline-block}.base{display:inline-block;min-inline-size:var(--_color-picker-min-inline-size, 280px)}.control{inline-size:100%}.button{display:inline-flex;box-sizing:border-box;align-items:center;border:0 none;border-radius:4px;margin:0;background-color:var(--button-color, var(--vvd-color-canvas-text));block-size:calc(1px*(32 + 4*clamp(-1,var(--vvd-size-density, 0),2)));color:var(--vvd-color-canvas);inline-size:calc(1px*(32 + 4*clamp(-1,var(--vvd-size-density, 0),2)));padding-inline:calc(1px*(32 + 4*clamp(-1,var(--vvd-size-density, 0),2))/4);text-decoration:none;vertical-align:middle}.button.contrast{color:var(--vvd-color-canvas-text)}.button:not(.disabled){cursor:pointer}.button.disabled{background-color:var(--vvd-color-neutral-300);color:var(--vvd-color-neutral-500);cursor:not-allowed}.button:focus-visible{--focus-stroke-gap-color: transparent;box-shadow:0 0 0 4px color-mix(in srgb,var(--vvd-color-cta-500),transparent 85%),inset 0 0 0 3px var(--focus-stroke-gap-color, currentColor);outline:1px solid var(--focus-stroke-color, var(--vvd-color-cta-500));outline-offset:calc(-1px - var(--focus-inset, 0px))}.button [data-vvd-component=icon]{font-size:calc(1px*(32 + 4*clamp(-1,var(--vvd-size-density, 0),2))/2);line-height:1}.dialog{display:flex;flex-direction:column;min-inline-size:var(--_color-picker-popup-min-inline-size, 264px)}.dialog .header{display:inline-flex;align-items:center;justify-content:space-between;padding-block:8px;padding-inline:16px}.dialog .header-title{font:var(--vvd-typography-base-extended-bold)}.dialog .body{display:flex;flex-direction:column;gap:16px;margin-block-end:16px;padding-inline:16px}.dialog .hex-input-wrapper{display:flex;align-items:stretch;gap:8px}.dialog .hex-input-wrapper [data-vvd-component=button]{flex:0 0 auto}.dialog .footer{padding:16px;border-top:1px solid var(--vvd-color-neutral-200)}.dialog .footer-title{display:block;margin-block-end:8px}.dialog .palette{gap:var(--_color-swatches-gap, 8px)}vvd-hex-input{min-width:0;flex:1 1 auto}vvd-hex-input::part(input){width:100%;height:100%;box-sizing:border-box;border:0 none;border-radius:8px;background-color:var(--vvd-color-canvas);box-shadow:inset 0 0 0 1px var(--vvd-color-neutral-500);font:var(--vvd-typography-base);outline:transparent;padding-inline:calc(1px*(40 + 4*clamp(-1,var(--vvd-size-density, 0),2))*.4)}vvd-hex-input::part(input):focus-visible{box-shadow:0 0 0 4px color-mix(in srgb,var(--vvd-color-cta-500),transparent 85%),inset 0 0 0 3px var(--focus-stroke-gap-color, currentColor);outline:1px solid var(--focus-stroke-color, var(--vvd-color-cta-500));outline-offset:calc(-1px - var(--focus-inset, 0px));--focus-stroke-gap-color: transparent}vvd-hex-picker{width:auto;height:auto;gap:16px;inline-size:100%}vvd-hex-picker::part(saturation){border-radius:8px;block-size:120px}vvd-hex-picker::part(hue){flex:0 0 8px;border-radius:8px}vvd-hex-picker::part(hue-pointer){width:10px;height:10px}vvd-hex-picker::part(saturation-pointer){width:18px;height:18px}::part(popup-base){inline-size:max-content;min-block-size:var(--_color-picker-popup-min-inline-size, 264px);min-inline-size:var(--_color-picker-popup-min-inline-size, 264px)}";
|
|
16
|
+
|
|
17
|
+
// Clamps a value between an upper and lower bound.
|
|
18
|
+
// We use ternary operators because it makes the minified code
|
|
19
|
+
// 2 times shorter then `Math.min(Math.max(a,b),c)`
|
|
20
|
+
const clamp = (number, min = 0, max = 1) => {
|
|
21
|
+
return number > max ? max : number < min ? min : number;
|
|
22
|
+
};
|
|
23
|
+
const round = (number, digits = 0, base = Math.pow(10, digits)) => {
|
|
24
|
+
return Math.round(base * number) / base;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const hexToHsva = (hex) => rgbaToHsva(hexToRgba(hex));
|
|
28
|
+
const hexToRgba = (hex) => {
|
|
29
|
+
if (hex[0] === '#')
|
|
30
|
+
hex = hex.substring(1);
|
|
31
|
+
if (hex.length < 6) {
|
|
32
|
+
return {
|
|
33
|
+
r: parseInt(hex[0] + hex[0], 16),
|
|
34
|
+
g: parseInt(hex[1] + hex[1], 16),
|
|
35
|
+
b: parseInt(hex[2] + hex[2], 16),
|
|
36
|
+
a: hex.length === 4 ? round(parseInt(hex[3] + hex[3], 16) / 255, 2) : 1
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
r: parseInt(hex.substring(0, 2), 16),
|
|
41
|
+
g: parseInt(hex.substring(2, 4), 16),
|
|
42
|
+
b: parseInt(hex.substring(4, 6), 16),
|
|
43
|
+
a: hex.length === 8 ? round(parseInt(hex.substring(6, 8), 16) / 255, 2) : 1
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
const hsvaToHex = (hsva) => rgbaToHex(hsvaToRgba(hsva));
|
|
47
|
+
const hsvaToHsla = ({ h, s, v, a }) => {
|
|
48
|
+
const hh = ((200 - s) * v) / 100;
|
|
49
|
+
return {
|
|
50
|
+
h: round(h),
|
|
51
|
+
s: round(hh > 0 && hh < 200 ? ((s * v) / 100 / (hh <= 100 ? hh : 200 - hh)) * 100 : 0),
|
|
52
|
+
l: round(hh / 2),
|
|
53
|
+
a: round(a, 2)
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
const hsvaToHslString = (hsva) => {
|
|
57
|
+
const { h, s, l } = hsvaToHsla(hsva);
|
|
58
|
+
return `hsl(${h}, ${s}%, ${l}%)`;
|
|
59
|
+
};
|
|
60
|
+
const hsvaToRgba = ({ h, s, v, a }) => {
|
|
61
|
+
h = (h / 360) * 6;
|
|
62
|
+
s = s / 100;
|
|
63
|
+
v = v / 100;
|
|
64
|
+
const hh = Math.floor(h), b = v * (1 - s), c = v * (1 - (h - hh) * s), d = v * (1 - (1 - h + hh) * s), module = hh % 6;
|
|
65
|
+
return {
|
|
66
|
+
r: round([v, c, b, b, d, v][module] * 255),
|
|
67
|
+
g: round([d, v, v, c, b, b][module] * 255),
|
|
68
|
+
b: round([b, b, d, v, v, c][module] * 255),
|
|
69
|
+
a: round(a, 2)
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
const format = (number) => {
|
|
73
|
+
const hex = number.toString(16);
|
|
74
|
+
return hex.length < 2 ? '0' + hex : hex;
|
|
75
|
+
};
|
|
76
|
+
const rgbaToHex = ({ r, g, b, a }) => {
|
|
77
|
+
const alphaHex = a < 1 ? format(round(a * 255)) : '';
|
|
78
|
+
return '#' + format(r) + format(g) + format(b) + alphaHex;
|
|
79
|
+
};
|
|
80
|
+
const rgbaToHsva = ({ r, g, b, a }) => {
|
|
81
|
+
const max = Math.max(r, g, b);
|
|
82
|
+
const delta = max - Math.min(r, g, b);
|
|
83
|
+
// prettier-ignore
|
|
84
|
+
const hh = delta
|
|
85
|
+
? max === r
|
|
86
|
+
? (g - b) / delta
|
|
87
|
+
: max === g
|
|
88
|
+
? 2 + (b - r) / delta
|
|
89
|
+
: 4 + (r - g) / delta
|
|
90
|
+
: 0;
|
|
91
|
+
return {
|
|
92
|
+
h: round(60 * (hh < 0 ? hh + 6 : hh)),
|
|
93
|
+
s: round(max ? (delta / max) * 100 : 0),
|
|
94
|
+
v: round((max / 255) * 100),
|
|
95
|
+
a
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const equalColorObjects = (first, second) => {
|
|
100
|
+
if (first === second)
|
|
101
|
+
return true;
|
|
102
|
+
for (const prop in first) {
|
|
103
|
+
// The following allows for a type-safe calling of this function (first & second have to be HSL, HSV, or RGB)
|
|
104
|
+
// with type-unsafe iterating over object keys. TS does not allow this without an index (`[key: string]: number`)
|
|
105
|
+
// on an object to define how iteration is normally done. To ensure extra keys are not allowed on our types,
|
|
106
|
+
// we must cast our object to unknown (as RGB demands `r` be a key, while `Record<string, x>` does not care if
|
|
107
|
+
// there is or not), and then as a type TS can iterate over.
|
|
108
|
+
if (first[prop] !==
|
|
109
|
+
second[prop])
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
};
|
|
114
|
+
const equalHex = (first, second) => {
|
|
115
|
+
if (first.toLowerCase() === second.toLowerCase())
|
|
116
|
+
return true;
|
|
117
|
+
// To compare colors like `#FFF` and `ffffff` we convert them into RGB objects
|
|
118
|
+
return equalColorObjects(hexToRgba(first), hexToRgba(second));
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const cache = {};
|
|
122
|
+
const tpl = (html) => {
|
|
123
|
+
let template = cache[html];
|
|
124
|
+
if (!template) {
|
|
125
|
+
template = document.createElement('template');
|
|
126
|
+
template.innerHTML = html;
|
|
127
|
+
cache[html] = template;
|
|
128
|
+
}
|
|
129
|
+
return template;
|
|
130
|
+
};
|
|
131
|
+
const fire = (target, type, detail) => {
|
|
132
|
+
target.dispatchEvent(new CustomEvent(type, {
|
|
133
|
+
bubbles: true,
|
|
134
|
+
detail
|
|
135
|
+
}));
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
let hasTouched = false;
|
|
139
|
+
// Check if an event was triggered by touch
|
|
140
|
+
const isTouch = (e) => 'touches' in e;
|
|
141
|
+
// Prevent mobile browsers from handling mouse events (conflicting with touch ones).
|
|
142
|
+
// If we detected a touch interaction before, we prefer reacting to touch events only.
|
|
143
|
+
const isValid = (event) => {
|
|
144
|
+
if (hasTouched && !isTouch(event))
|
|
145
|
+
return false;
|
|
146
|
+
if (!hasTouched)
|
|
147
|
+
hasTouched = isTouch(event);
|
|
148
|
+
return true;
|
|
149
|
+
};
|
|
150
|
+
const pointerMove = (target, event) => {
|
|
151
|
+
const pointer = isTouch(event) ? event.touches[0] : event;
|
|
152
|
+
const rect = target.el.getBoundingClientRect();
|
|
153
|
+
fire(target.el, 'move', target.getMove({
|
|
154
|
+
x: clamp((pointer.pageX - (rect.left + window.pageXOffset)) / rect.width),
|
|
155
|
+
y: clamp((pointer.pageY - (rect.top + window.pageYOffset)) / rect.height)
|
|
156
|
+
}));
|
|
157
|
+
};
|
|
158
|
+
const keyMove = (target, event) => {
|
|
159
|
+
// We use `keyCode` instead of `key` to reduce the size of the library.
|
|
160
|
+
const keyCode = event.keyCode;
|
|
161
|
+
// Ignore all keys except arrow ones, Page Up, Page Down, Home and End.
|
|
162
|
+
if (keyCode > 40 || (target.xy && keyCode < 37) || keyCode < 33)
|
|
163
|
+
return;
|
|
164
|
+
// Do not scroll page by keys when color picker element has focus.
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
// Send relative offset to the parent component.
|
|
167
|
+
fire(target.el, 'move', target.getMove({
|
|
168
|
+
x: keyCode === 39 // Arrow Right
|
|
169
|
+
? 0.01
|
|
170
|
+
: keyCode === 37 // Arrow Left
|
|
171
|
+
? -0.01
|
|
172
|
+
: keyCode === 34 // Page Down
|
|
173
|
+
? 0.05
|
|
174
|
+
: keyCode === 33 // Page Up
|
|
175
|
+
? -0.05
|
|
176
|
+
: keyCode === 35 // End
|
|
177
|
+
? 1
|
|
178
|
+
: keyCode === 36 // Home
|
|
179
|
+
? -1
|
|
180
|
+
: 0,
|
|
181
|
+
y: keyCode === 40 // Arrow down
|
|
182
|
+
? 0.01
|
|
183
|
+
: keyCode === 38 // Arrow Up
|
|
184
|
+
? -0.01
|
|
185
|
+
: 0
|
|
186
|
+
}, true));
|
|
187
|
+
};
|
|
188
|
+
class Slider {
|
|
189
|
+
constructor(root, part, aria, xy) {
|
|
190
|
+
const template = tpl(`<div role="slider" tabindex="0" part="${part}" ${aria}><div part="${part}-pointer"></div></div>`);
|
|
191
|
+
root.appendChild(template.content.cloneNode(true));
|
|
192
|
+
const el = root.querySelector(`[part=${part}]`);
|
|
193
|
+
el.addEventListener('mousedown', this);
|
|
194
|
+
el.addEventListener('touchstart', this);
|
|
195
|
+
el.addEventListener('keydown', this);
|
|
196
|
+
this.el = el;
|
|
197
|
+
this.xy = xy;
|
|
198
|
+
this.nodes = [el.firstChild, el];
|
|
199
|
+
}
|
|
200
|
+
set dragging(state) {
|
|
201
|
+
const toggleEvent = state ? document.addEventListener : document.removeEventListener;
|
|
202
|
+
toggleEvent(hasTouched ? 'touchmove' : 'mousemove', this);
|
|
203
|
+
toggleEvent(hasTouched ? 'touchend' : 'mouseup', this);
|
|
204
|
+
}
|
|
205
|
+
handleEvent(event) {
|
|
206
|
+
switch (event.type) {
|
|
207
|
+
case 'mousedown':
|
|
208
|
+
case 'touchstart':
|
|
209
|
+
event.preventDefault();
|
|
210
|
+
// event.button is 0 in mousedown for left button activation
|
|
211
|
+
if (!isValid(event) || (!hasTouched && event.button != 0))
|
|
212
|
+
return;
|
|
213
|
+
this.el.focus();
|
|
214
|
+
pointerMove(this, event);
|
|
215
|
+
this.dragging = true;
|
|
216
|
+
break;
|
|
217
|
+
case 'mousemove':
|
|
218
|
+
case 'touchmove':
|
|
219
|
+
event.preventDefault();
|
|
220
|
+
pointerMove(this, event);
|
|
221
|
+
break;
|
|
222
|
+
case 'mouseup':
|
|
223
|
+
case 'touchend':
|
|
224
|
+
this.dragging = false;
|
|
225
|
+
break;
|
|
226
|
+
case 'keydown':
|
|
227
|
+
keyMove(this, event);
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
style(styles) {
|
|
232
|
+
styles.forEach((style, i) => {
|
|
233
|
+
for (const p in style) {
|
|
234
|
+
this.nodes[i].style.setProperty(p, style[p]);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
class Hue extends Slider {
|
|
241
|
+
constructor(root) {
|
|
242
|
+
super(root, 'hue', 'aria-label="Hue" aria-valuemin="0" aria-valuemax="360"', false);
|
|
243
|
+
}
|
|
244
|
+
update({ h }) {
|
|
245
|
+
this.h = h;
|
|
246
|
+
this.style([
|
|
247
|
+
{
|
|
248
|
+
left: `${(h / 360) * 100}%`,
|
|
249
|
+
color: hsvaToHslString({ h, s: 100, v: 100, a: 1 })
|
|
250
|
+
}
|
|
251
|
+
]);
|
|
252
|
+
this.el.setAttribute('aria-valuenow', `${round(h)}`);
|
|
253
|
+
}
|
|
254
|
+
getMove(offset, key) {
|
|
255
|
+
// Hue measured in degrees of the color circle ranging from 0 to 360
|
|
256
|
+
return { h: key ? clamp(this.h + offset.x * 360, 0, 360) : 360 * offset.x };
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
class Saturation extends Slider {
|
|
261
|
+
constructor(root) {
|
|
262
|
+
super(root, 'saturation', 'aria-label="Color"', true);
|
|
263
|
+
}
|
|
264
|
+
update(hsva) {
|
|
265
|
+
this.hsva = hsva;
|
|
266
|
+
this.style([
|
|
267
|
+
{
|
|
268
|
+
top: `${100 - hsva.v}%`,
|
|
269
|
+
left: `${hsva.s}%`,
|
|
270
|
+
color: hsvaToHslString(hsva)
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
'background-color': hsvaToHslString({ h: hsva.h, s: 100, v: 100, a: 1 })
|
|
274
|
+
}
|
|
275
|
+
]);
|
|
276
|
+
this.el.setAttribute('aria-valuetext', `Saturation ${round(hsva.s)}%, Brightness ${round(hsva.v)}%`);
|
|
277
|
+
}
|
|
278
|
+
getMove(offset, key) {
|
|
279
|
+
// Saturation and brightness always fit into [0, 100] range
|
|
280
|
+
return {
|
|
281
|
+
s: key ? clamp(this.hsva.s + offset.x * 100, 0, 100) : offset.x * 100,
|
|
282
|
+
v: key ? clamp(this.hsva.v - offset.y * 100, 0, 100) : Math.round(100 - offset.y * 100)
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const css = `:host{display:flex;flex-direction:column;position:relative;width:200px;height:200px;user-select:none;-webkit-user-select:none;cursor:default}:host([hidden]){display:none!important}[role=slider]{position:relative;touch-action:none;user-select:none;-webkit-user-select:none;outline:0}[role=slider]:last-child{border-radius:0 0 8px 8px}[part$=pointer]{position:absolute;z-index:1;box-sizing:border-box;width:28px;height:28px;display:flex;place-content:center center;transform:translate(-50%,-50%);background-color:#fff;border:2px solid #fff;border-radius:50%;box-shadow:0 2px 4px rgba(0,0,0,.2)}[part$=pointer]::after{content:"";width:100%;height:100%;border-radius:inherit;background-color:currentColor}[role=slider]:focus [part$=pointer]{transform:translate(-50%,-50%) scale(1.1)}`;
|
|
288
|
+
|
|
289
|
+
const hueCss = `[part=hue]{flex:0 0 24px;background:linear-gradient(to right,red 0,#ff0 17%,#0f0 33%,#0ff 50%,#00f 67%,#f0f 83%,red 100%)}[part=hue-pointer]{top:50%;z-index:2}`;
|
|
290
|
+
|
|
291
|
+
const saturationCss = `[part=saturation]{flex-grow:1;border-color:transparent;border-bottom:12px solid #000;border-radius:8px 8px 0 0;background-image:linear-gradient(to top,#000,transparent),linear-gradient(to right,#fff,rgba(255,255,255,0));box-shadow:inset 0 0 0 1px rgba(0,0,0,.05)}[part=saturation-pointer]{z-index:3}`;
|
|
292
|
+
|
|
293
|
+
const $isSame = Symbol('same');
|
|
294
|
+
const $color$1 = Symbol('color');
|
|
295
|
+
const $hsva = Symbol('hsva');
|
|
296
|
+
const $update$1 = Symbol('update');
|
|
297
|
+
const $parts = Symbol('parts');
|
|
298
|
+
const $css = Symbol('css');
|
|
299
|
+
const $sliders = Symbol('sliders');
|
|
300
|
+
let ColorPicker$1 = class ColorPicker extends HTMLElement {
|
|
301
|
+
static get observedAttributes() {
|
|
302
|
+
return ['color'];
|
|
303
|
+
}
|
|
304
|
+
get [$css]() {
|
|
305
|
+
return [css, hueCss, saturationCss];
|
|
306
|
+
}
|
|
307
|
+
get [$sliders]() {
|
|
308
|
+
return [Saturation, Hue];
|
|
309
|
+
}
|
|
310
|
+
get color() {
|
|
311
|
+
return this[$color$1];
|
|
312
|
+
}
|
|
313
|
+
set color(newColor) {
|
|
314
|
+
if (!this[$isSame](newColor)) {
|
|
315
|
+
const newHsva = this.colorModel.toHsva(newColor);
|
|
316
|
+
this[$update$1](newHsva);
|
|
317
|
+
this[$color$1] = newColor;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
constructor() {
|
|
321
|
+
super();
|
|
322
|
+
const template = tpl(`<style>${this[$css].join('')}</style>`);
|
|
323
|
+
const root = this.attachShadow({ mode: 'open' });
|
|
324
|
+
root.appendChild(template.content.cloneNode(true));
|
|
325
|
+
root.addEventListener('move', this);
|
|
326
|
+
this[$parts] = this[$sliders].map((slider) => new slider(root));
|
|
327
|
+
}
|
|
328
|
+
connectedCallback() {
|
|
329
|
+
// A user may set a property on an _instance_ of an element,
|
|
330
|
+
// before its prototype has been connected to this class.
|
|
331
|
+
// If so, we need to run it through the proper class setter.
|
|
332
|
+
if (this.hasOwnProperty('color')) {
|
|
333
|
+
const value = this.color;
|
|
334
|
+
delete this['color'];
|
|
335
|
+
this.color = value;
|
|
336
|
+
}
|
|
337
|
+
else if (!this.color) {
|
|
338
|
+
this.color = this.colorModel.defaultColor;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
attributeChangedCallback(_attr, _oldVal, newVal) {
|
|
342
|
+
const color = this.colorModel.fromAttr(newVal);
|
|
343
|
+
if (!this[$isSame](color)) {
|
|
344
|
+
this.color = color;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
handleEvent(event) {
|
|
348
|
+
// Merge the current HSV color object with updated params.
|
|
349
|
+
const oldHsva = this[$hsva];
|
|
350
|
+
const newHsva = { ...oldHsva, ...event.detail };
|
|
351
|
+
this[$update$1](newHsva);
|
|
352
|
+
let newColor;
|
|
353
|
+
if (!equalColorObjects(newHsva, oldHsva) &&
|
|
354
|
+
!this[$isSame]((newColor = this.colorModel.fromHsva(newHsva)))) {
|
|
355
|
+
this[$color$1] = newColor;
|
|
356
|
+
fire(this, 'color-changed', { value: newColor });
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
[$isSame](color) {
|
|
360
|
+
return this.color && this.colorModel.equal(color, this.color);
|
|
361
|
+
}
|
|
362
|
+
[$update$1](hsva) {
|
|
363
|
+
this[$hsva] = hsva;
|
|
364
|
+
this[$parts].forEach((part) => part.update(hsva));
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
const colorModel = {
|
|
369
|
+
defaultColor: '#000',
|
|
370
|
+
toHsva: hexToHsva,
|
|
371
|
+
fromHsva: ({ h, s, v }) => hsvaToHex({ h, s, v, a: 1 }),
|
|
372
|
+
equal: equalHex,
|
|
373
|
+
fromAttr: (color) => color
|
|
374
|
+
};
|
|
375
|
+
class HexBase extends ColorPicker$1 {
|
|
376
|
+
get colorModel() {
|
|
377
|
+
return colorModel;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* A color picker custom element that uses HEX format.
|
|
383
|
+
*
|
|
384
|
+
* @element hex-color-picker
|
|
385
|
+
*
|
|
386
|
+
* @prop {string} color - Selected color in HEX format.
|
|
387
|
+
* @attr {string} color - Selected color in HEX format.
|
|
388
|
+
*
|
|
389
|
+
* @fires color-changed - Event fired when color property changes.
|
|
390
|
+
*
|
|
391
|
+
* @csspart hue - A hue selector container.
|
|
392
|
+
* @csspart saturation - A saturation selector container
|
|
393
|
+
* @csspart hue-pointer - A hue pointer element.
|
|
394
|
+
* @csspart saturation-pointer - A saturation pointer element.
|
|
395
|
+
*/
|
|
396
|
+
class HexColorPicker extends HexBase {
|
|
397
|
+
}
|
|
398
|
+
customElements.define('hex-color-picker', HexColorPicker);
|
|
399
|
+
|
|
400
|
+
const matcher = /^#?([0-9A-F]{3,8})$/i;
|
|
401
|
+
const validHex = (value, alpha) => {
|
|
402
|
+
const match = matcher.exec(value);
|
|
403
|
+
const length = match ? match[1].length : 0;
|
|
404
|
+
return (length === 3 || // '#rgb' format
|
|
405
|
+
length === 6 || // '#rrggbb' format
|
|
406
|
+
(!!alpha && length === 4) || // '#rgba' format
|
|
407
|
+
(!!alpha && length === 8) // '#rrggbbaa' format
|
|
408
|
+
);
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
const template = tpl('<slot><input part="input" spellcheck="false"></slot>');
|
|
412
|
+
// Escapes all non-hexadecimal characters including "#"
|
|
413
|
+
const escape = (hex, alpha) => hex.replace(/([^0-9A-F]+)/gi, '').substring(0, alpha ? 8 : 6);
|
|
414
|
+
const $alpha = Symbol('alpha');
|
|
415
|
+
const $color = Symbol('color');
|
|
416
|
+
const $saved = Symbol('saved');
|
|
417
|
+
const $input = Symbol('input');
|
|
418
|
+
const $init = Symbol('init');
|
|
419
|
+
const $prefix = Symbol('prefix');
|
|
420
|
+
const $update = Symbol('update');
|
|
421
|
+
class HexInputBase extends HTMLElement {
|
|
422
|
+
static get observedAttributes() {
|
|
423
|
+
return ['alpha', 'color', 'prefixed'];
|
|
424
|
+
}
|
|
425
|
+
get color() {
|
|
426
|
+
return this[$color];
|
|
427
|
+
}
|
|
428
|
+
set color(hex) {
|
|
429
|
+
this[$color] = hex;
|
|
430
|
+
this[$update](hex);
|
|
431
|
+
}
|
|
432
|
+
get alpha() {
|
|
433
|
+
return this[$alpha];
|
|
434
|
+
}
|
|
435
|
+
set alpha(alpha) {
|
|
436
|
+
this[$alpha] = alpha;
|
|
437
|
+
this.toggleAttribute('alpha', alpha);
|
|
438
|
+
// When alpha set to false, update color
|
|
439
|
+
const color = this.color;
|
|
440
|
+
if (color && !validHex(color, alpha)) {
|
|
441
|
+
this.color = color.startsWith('#')
|
|
442
|
+
? color.substring(0, color.length === 5 ? 4 : 7)
|
|
443
|
+
: color.substring(0, color.length === 4 ? 3 : 6);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
get prefixed() {
|
|
447
|
+
return this[$prefix];
|
|
448
|
+
}
|
|
449
|
+
set prefixed(prefixed) {
|
|
450
|
+
this[$prefix] = prefixed;
|
|
451
|
+
this.toggleAttribute('prefixed', prefixed);
|
|
452
|
+
this[$update](this.color);
|
|
453
|
+
}
|
|
454
|
+
constructor() {
|
|
455
|
+
super();
|
|
456
|
+
const root = this.attachShadow({ mode: 'open' });
|
|
457
|
+
root.appendChild(template.content.cloneNode(true));
|
|
458
|
+
const slot = root.firstElementChild;
|
|
459
|
+
slot.addEventListener('slotchange', () => this[$init](root));
|
|
460
|
+
}
|
|
461
|
+
connectedCallback() {
|
|
462
|
+
this[$init](this.shadowRoot);
|
|
463
|
+
// A user may set a property on an _instance_ of an element,
|
|
464
|
+
// before its prototype has been connected to this class.
|
|
465
|
+
// If so, we need to run it through the proper class setter.
|
|
466
|
+
if (this.hasOwnProperty('alpha')) {
|
|
467
|
+
const value = this.alpha;
|
|
468
|
+
delete this['alpha'];
|
|
469
|
+
this.alpha = value;
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
this.alpha = this.hasAttribute('alpha');
|
|
473
|
+
}
|
|
474
|
+
if (this.hasOwnProperty('prefixed')) {
|
|
475
|
+
const value = this.prefixed;
|
|
476
|
+
delete this['prefixed'];
|
|
477
|
+
this.prefixed = value;
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
this.prefixed = this.hasAttribute('prefixed');
|
|
481
|
+
}
|
|
482
|
+
if (this.hasOwnProperty('color')) {
|
|
483
|
+
const value = this.color;
|
|
484
|
+
delete this['color'];
|
|
485
|
+
this.color = value;
|
|
486
|
+
}
|
|
487
|
+
else if (this.color == null) {
|
|
488
|
+
this.color = this.getAttribute('color') || '';
|
|
489
|
+
}
|
|
490
|
+
else if (this[$color]) {
|
|
491
|
+
this[$update](this[$color]);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
handleEvent(event) {
|
|
495
|
+
const target = event.target;
|
|
496
|
+
const { value } = target;
|
|
497
|
+
switch (event.type) {
|
|
498
|
+
case 'input':
|
|
499
|
+
const hex = escape(value, this.alpha);
|
|
500
|
+
this[$saved] = this.color;
|
|
501
|
+
if (validHex(hex, this.alpha) || value === '') {
|
|
502
|
+
this.color = hex;
|
|
503
|
+
this.dispatchEvent(new CustomEvent('color-changed', {
|
|
504
|
+
bubbles: true,
|
|
505
|
+
detail: { value: hex ? '#' + hex : '' }
|
|
506
|
+
}));
|
|
507
|
+
}
|
|
508
|
+
break;
|
|
509
|
+
case 'blur':
|
|
510
|
+
if (value && !validHex(value, this.alpha)) {
|
|
511
|
+
this.color = this[$saved];
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
attributeChangedCallback(attr, _oldVal, newVal) {
|
|
516
|
+
if (attr === 'color' && this.color !== newVal) {
|
|
517
|
+
this.color = newVal;
|
|
518
|
+
}
|
|
519
|
+
const hasBooleanAttr = newVal != null;
|
|
520
|
+
if (attr === 'alpha') {
|
|
521
|
+
if (this.alpha !== hasBooleanAttr) {
|
|
522
|
+
this.alpha = hasBooleanAttr;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if (attr === 'prefixed') {
|
|
526
|
+
if (this.prefixed !== hasBooleanAttr) {
|
|
527
|
+
this.prefixed = hasBooleanAttr;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
[$init](root) {
|
|
532
|
+
let input = this.querySelector('input');
|
|
533
|
+
if (!input) {
|
|
534
|
+
// remove all child node if no input found
|
|
535
|
+
let c;
|
|
536
|
+
while ((c = this.firstChild)) {
|
|
537
|
+
c.remove();
|
|
538
|
+
}
|
|
539
|
+
input = root.querySelector('input');
|
|
540
|
+
}
|
|
541
|
+
input.addEventListener('input', this);
|
|
542
|
+
input.addEventListener('blur', this);
|
|
543
|
+
this[$input] = input;
|
|
544
|
+
this[$update](this.color);
|
|
545
|
+
}
|
|
546
|
+
[$update](hex) {
|
|
547
|
+
if (this[$input]) {
|
|
548
|
+
this[$input].value =
|
|
549
|
+
hex == null || hex == '' ? '' : (this.prefixed ? '#' : '') + escape(hex, this.alpha);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* A custom element for entering color in HEX format.
|
|
556
|
+
*
|
|
557
|
+
* @element hex-input
|
|
558
|
+
*
|
|
559
|
+
* @prop {string} color - Color in HEX format.
|
|
560
|
+
* @attr {string} color - Selected color in HEX format.
|
|
561
|
+
* @prop {boolean} alpha - When true, `#rgba` and `#rrggbbaa` color formats are allowed.
|
|
562
|
+
* @attr {boolean} alpha - Allows `#rgba` and `#rrggbbaa` color formats.
|
|
563
|
+
* @prop {boolean} prefixed - When true, `#` prefix is displayed in the input.
|
|
564
|
+
* @attr {boolean} prefixed - Enables `#` prefix displaying.
|
|
565
|
+
*
|
|
566
|
+
* @fires color-changed - Event fired when color is changed.
|
|
567
|
+
*
|
|
568
|
+
* @csspart input - A native input element.
|
|
569
|
+
*/
|
|
570
|
+
class HexInput extends HexInputBase {
|
|
571
|
+
}
|
|
572
|
+
customElements.define('hex-input', HexInput);
|
|
573
|
+
|
|
574
|
+
var __defProp = Object.defineProperty;
|
|
575
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
576
|
+
var result = void 0 ;
|
|
577
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
578
|
+
if (decorator = decorators[i])
|
|
579
|
+
result = (decorator(target, key, result) ) || result;
|
|
580
|
+
if (result) __defProp(target, key, result);
|
|
581
|
+
return result;
|
|
582
|
+
};
|
|
583
|
+
const VC_HEX_PICKER_TAG = "vvd-hex-picker";
|
|
584
|
+
const VC_HEX_INPUT_TAG = "vvd-hex-input";
|
|
585
|
+
class VvdHexPicker extends HexColorPicker {
|
|
586
|
+
static {
|
|
587
|
+
this.displayName = "VvdHexPicker";
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
class VvdHexInput extends HexInput {
|
|
591
|
+
static {
|
|
592
|
+
this.displayName = "VvdHexInput";
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
if (!customElements.get(VC_HEX_PICKER_TAG)) {
|
|
596
|
+
customElements.define(VC_HEX_PICKER_TAG, VvdHexPicker);
|
|
597
|
+
}
|
|
598
|
+
if (!customElements.get(VC_HEX_INPUT_TAG)) {
|
|
599
|
+
customElements.define(VC_HEX_INPUT_TAG, VvdHexInput);
|
|
600
|
+
}
|
|
601
|
+
const vcPickerTag = VC_HEX_PICKER_TAG;
|
|
602
|
+
const vcInputTag = VC_HEX_INPUT_TAG;
|
|
603
|
+
class ColorPicker extends WithContextualHelp(
|
|
604
|
+
WithFeedback(
|
|
605
|
+
WithErrorText(WithSuccessText(DelegatesAria(BaseColorPicker(VividElement))))
|
|
606
|
+
)
|
|
607
|
+
) {
|
|
608
|
+
constructor() {
|
|
609
|
+
super(...arguments);
|
|
610
|
+
this.disableSavedColors = false;
|
|
611
|
+
this.savedColors = [];
|
|
612
|
+
this.maxSwatches = 6;
|
|
613
|
+
this.copyIconName = "copy-2-line";
|
|
614
|
+
this.#iconResetTimer = null;
|
|
615
|
+
/**
|
|
616
|
+
* @internal
|
|
617
|
+
*/
|
|
618
|
+
this._copyValueToClipboard = async (value) => {
|
|
619
|
+
try {
|
|
620
|
+
await navigator.clipboard.writeText(value);
|
|
621
|
+
this._setTemporaryCopyIcon("check-circle-line");
|
|
622
|
+
} catch {
|
|
623
|
+
alert(this.locale?.colorPicker?.copyErrorText);
|
|
624
|
+
this._setTemporaryCopyIcon("error-line");
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
/**
|
|
628
|
+
* @internal
|
|
629
|
+
*/
|
|
630
|
+
this.#closeOnPointerOutside = (e) => {
|
|
631
|
+
if (this._isInPath(e, this._buttonEl) || this._isInPath(e, this._popupEl)) {
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
this.open = false;
|
|
635
|
+
};
|
|
636
|
+
/**
|
|
637
|
+
* @internal
|
|
638
|
+
*/
|
|
639
|
+
this.#closeOnEscape = (e) => {
|
|
640
|
+
if (e.key === "Escape") {
|
|
641
|
+
this.open = false;
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
static {
|
|
646
|
+
/**
|
|
647
|
+
* Regular expression pattern for valid hex colors (with # prefix)
|
|
648
|
+
* Matches both 3-digit (#abc) and 6-digit (#aabbcc) hex colors
|
|
649
|
+
* @internal
|
|
650
|
+
*/
|
|
651
|
+
this.HEX_COLOR_PATTERN = /^#(([0-9a-fA-F]{2}){3}|([0-9a-fA-F]){3})$/;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* @internal
|
|
655
|
+
*/
|
|
656
|
+
placeholderChanged() {
|
|
657
|
+
if (this.proxy instanceof HTMLInputElement) {
|
|
658
|
+
this.proxy.placeholder = this.placeholder;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Change event handler for inner control.
|
|
663
|
+
* @remarks
|
|
664
|
+
* @internal
|
|
665
|
+
*/
|
|
666
|
+
handleChange() {
|
|
667
|
+
this.$emit("change");
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* @internal
|
|
671
|
+
*/
|
|
672
|
+
savedColorsKeyChanged() {
|
|
673
|
+
this.savedColors = this._loadSavedColors();
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* @internal
|
|
677
|
+
*/
|
|
678
|
+
get _savedColorsStorageKey() {
|
|
679
|
+
if (this.savedColorsKey) return this.savedColorsKey;
|
|
680
|
+
const tag = this.tagName.toLowerCase();
|
|
681
|
+
return `vvd-saved-colors:${tag}`;
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* @internal
|
|
685
|
+
*/
|
|
686
|
+
_handleColorSaving() {
|
|
687
|
+
this._saveCurrentColor();
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* @internal
|
|
691
|
+
*/
|
|
692
|
+
get _maxSwatchesNormalized() {
|
|
693
|
+
return Number.isFinite(this.maxSwatches) ? Math.max(0, Math.floor(this.maxSwatches)) : 0;
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* @internal
|
|
697
|
+
*/
|
|
698
|
+
maxSwatchesChanged() {
|
|
699
|
+
const maxCount = this._maxSwatchesNormalized;
|
|
700
|
+
if (this.savedColors?.length > maxCount) {
|
|
701
|
+
this.savedColors = this.savedColors.slice(0, maxCount);
|
|
702
|
+
this._setSavedColors(this.savedColors);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* @internal
|
|
707
|
+
*/
|
|
708
|
+
_onPickerColorChanged(e) {
|
|
709
|
+
if (typeof e.detail?.value === "string") {
|
|
710
|
+
this.value = e.detail?.value;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* @internal
|
|
715
|
+
*/
|
|
716
|
+
valueChanged(_oldVal, newVal) {
|
|
717
|
+
if (this._vcHexPickerEl && typeof newVal === "string") {
|
|
718
|
+
this._vcHexPickerEl.color = newVal;
|
|
719
|
+
}
|
|
720
|
+
if (this._vcHexInputEl && typeof newVal === "string") {
|
|
721
|
+
this._vcHexInputEl.color = newVal;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* @internal
|
|
726
|
+
*/
|
|
727
|
+
_onTextFieldInput(event) {
|
|
728
|
+
const textField = event.currentTarget;
|
|
729
|
+
this.value = textField.value;
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* @internal
|
|
733
|
+
*/
|
|
734
|
+
get _buttonColor() {
|
|
735
|
+
if (!this._canvasColor) {
|
|
736
|
+
this._refreshCanvasColor();
|
|
737
|
+
}
|
|
738
|
+
if (this.value && isValidHexColor(this.value)) {
|
|
739
|
+
return this.value;
|
|
740
|
+
}
|
|
741
|
+
return "var(--vvd-color-canvas-text)";
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* @internal
|
|
745
|
+
*/
|
|
746
|
+
_onButtonClick() {
|
|
747
|
+
this.open = !this.open;
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* @internal
|
|
751
|
+
*/
|
|
752
|
+
_handleCloseRequest() {
|
|
753
|
+
this.open = false;
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* @internal
|
|
757
|
+
*/
|
|
758
|
+
_isInPath(e, el) {
|
|
759
|
+
if (!el) return false;
|
|
760
|
+
const path = e.composedPath?.();
|
|
761
|
+
return !!(path && path.includes(el));
|
|
762
|
+
}
|
|
763
|
+
#iconResetTimer;
|
|
764
|
+
/**
|
|
765
|
+
* @internal
|
|
766
|
+
*/
|
|
767
|
+
_setTemporaryCopyIcon(name, ms = 2e3) {
|
|
768
|
+
this.copyIconName = name;
|
|
769
|
+
if (this.#iconResetTimer) clearTimeout(this.#iconResetTimer);
|
|
770
|
+
this.#iconResetTimer = setTimeout(() => {
|
|
771
|
+
this.copyIconName = "copy-2-line";
|
|
772
|
+
this.#iconResetTimer = null;
|
|
773
|
+
}, ms);
|
|
774
|
+
}
|
|
775
|
+
connectedCallback() {
|
|
776
|
+
super.connectedCallback();
|
|
777
|
+
this._refreshCanvasColor();
|
|
778
|
+
this.savedColors = this._loadSavedColors();
|
|
779
|
+
document.addEventListener("mousedown", this.#closeOnPointerOutside, true);
|
|
780
|
+
document.addEventListener("keydown", this.#closeOnEscape);
|
|
781
|
+
}
|
|
782
|
+
disconnectedCallback() {
|
|
783
|
+
super.disconnectedCallback();
|
|
784
|
+
document.removeEventListener(
|
|
785
|
+
"mousedown",
|
|
786
|
+
this.#closeOnPointerOutside,
|
|
787
|
+
true
|
|
788
|
+
);
|
|
789
|
+
document.removeEventListener("keydown", this.#closeOnEscape);
|
|
790
|
+
}
|
|
791
|
+
#closeOnPointerOutside;
|
|
792
|
+
#closeOnEscape;
|
|
793
|
+
/**
|
|
794
|
+
* @internal
|
|
795
|
+
*/
|
|
796
|
+
_saveCurrentColor() {
|
|
797
|
+
const value = this.value;
|
|
798
|
+
if (typeof value !== "string" || !isValidHexColor(value)) return;
|
|
799
|
+
const swatches = Array.isArray(this.savedColors) ? [...this.savedColors] : [];
|
|
800
|
+
const idx = swatches.findIndex((s) => s?.value === value);
|
|
801
|
+
if (idx !== -1) swatches.splice(idx, 1);
|
|
802
|
+
swatches.unshift({ value });
|
|
803
|
+
this.savedColors = swatches.slice(0, this._maxSwatchesNormalized);
|
|
804
|
+
this._setSavedColors(this.savedColors);
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* @internal
|
|
808
|
+
*/
|
|
809
|
+
_loadSavedColors() {
|
|
810
|
+
try {
|
|
811
|
+
const savedColors = localStorage.getItem(this._savedColorsStorageKey);
|
|
812
|
+
if (!savedColors) return [];
|
|
813
|
+
const parsed = JSON.parse(savedColors);
|
|
814
|
+
if (!Array.isArray(parsed)) return [];
|
|
815
|
+
return parsed.filter(
|
|
816
|
+
(x) => x && typeof x.value === "string" && isValidHexColor(x.value)
|
|
817
|
+
).map((x) => ({
|
|
818
|
+
value: x.value,
|
|
819
|
+
label: typeof x.label === "string" ? x.label : void 0
|
|
820
|
+
}));
|
|
821
|
+
} catch {
|
|
822
|
+
return [];
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* @internal
|
|
827
|
+
*/
|
|
828
|
+
_setSavedColors(swatches) {
|
|
829
|
+
try {
|
|
830
|
+
localStorage.setItem(
|
|
831
|
+
this._savedColorsStorageKey,
|
|
832
|
+
JSON.stringify(swatches)
|
|
833
|
+
);
|
|
834
|
+
} catch {
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Get all color swatches combined, both from swatches property and saved colors
|
|
839
|
+
* @internal
|
|
840
|
+
*/
|
|
841
|
+
get allSwatches() {
|
|
842
|
+
const predefinedColors = Array.isArray(this.swatches) ? this.swatches : [];
|
|
843
|
+
const savedColors = Array.isArray(this.savedColors) ? this.savedColors : [];
|
|
844
|
+
const seen = /* @__PURE__ */ new Set();
|
|
845
|
+
const merged = [];
|
|
846
|
+
const appendIfUniqueAndValid = (swatch) => {
|
|
847
|
+
if (!swatch || typeof swatch.value !== "string") return;
|
|
848
|
+
if (!isValidHexColor(swatch.value) || seen.has(swatch.value)) return;
|
|
849
|
+
seen.add(swatch.value);
|
|
850
|
+
merged.push(swatch);
|
|
851
|
+
};
|
|
852
|
+
if (!this.disableSavedColors) {
|
|
853
|
+
savedColors.forEach(appendIfUniqueAndValid);
|
|
854
|
+
}
|
|
855
|
+
predefinedColors.forEach(appendIfUniqueAndValid);
|
|
856
|
+
return merged.slice(0, this._maxSwatchesNormalized);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
__decorateClass([
|
|
860
|
+
attr
|
|
861
|
+
], ColorPicker.prototype, "placeholder");
|
|
862
|
+
__decorateClass([
|
|
863
|
+
attr({ attribute: "saved-colors-key" })
|
|
864
|
+
], ColorPicker.prototype, "savedColorsKey");
|
|
865
|
+
__decorateClass([
|
|
866
|
+
attr({
|
|
867
|
+
mode: "boolean",
|
|
868
|
+
attribute: "disable-saved-colors"
|
|
869
|
+
})
|
|
870
|
+
], ColorPicker.prototype, "disableSavedColors");
|
|
871
|
+
__decorateClass([
|
|
872
|
+
observable
|
|
873
|
+
], ColorPicker.prototype, "savedColors");
|
|
874
|
+
__decorateClass([
|
|
875
|
+
attr({
|
|
876
|
+
attribute: "max-swatches",
|
|
877
|
+
mode: "fromView",
|
|
878
|
+
converter: nullableNumberConverter
|
|
879
|
+
})
|
|
880
|
+
], ColorPicker.prototype, "maxSwatches");
|
|
881
|
+
__decorateClass([
|
|
882
|
+
observable
|
|
883
|
+
], ColorPicker.prototype, "copyIconName");
|
|
884
|
+
|
|
885
|
+
function renderTextField(textFieldTag, iconTag) {
|
|
886
|
+
const getClasses = (_) => classNames("control");
|
|
887
|
+
return html`
|
|
888
|
+
<${textFieldTag}
|
|
889
|
+
id="text-field"
|
|
890
|
+
class="${getClasses}"
|
|
891
|
+
pattern="${ColorPicker.HEX_COLOR_PATTERN.source}"
|
|
892
|
+
maxlength="7"
|
|
893
|
+
label="${(x) => x.label}"
|
|
894
|
+
:value="${(x) => x.value}"
|
|
895
|
+
placeholder="${(x) => x.placeholder}"
|
|
896
|
+
helper-text="${(x) => x.helperText}"
|
|
897
|
+
error-text="${(x) => x.errorValidationMessage}"
|
|
898
|
+
success-text="${(x) => x.successText}"
|
|
899
|
+
?disabled="${(x) => x.disabled}"
|
|
900
|
+
?required="${(x) => x.required}"
|
|
901
|
+
@input='${(x, c) => x._onTextFieldInput(c.event)}'
|
|
902
|
+
@change="${(x) => x.handleChange()}"
|
|
903
|
+
@blur="${(x) => {
|
|
904
|
+
x.$emit("blur", void 0, { bubbles: false });
|
|
905
|
+
}}"
|
|
906
|
+
@focus="${(x) => {
|
|
907
|
+
x.$emit("focus", void 0, { bubbles: false });
|
|
908
|
+
}}"
|
|
909
|
+
${delegateAria()}
|
|
910
|
+
${ref("_textFieldEl")}
|
|
911
|
+
>
|
|
912
|
+
<button
|
|
913
|
+
aria-label="${(x) => x.locale.colorPicker.pickerButtonLabel}"
|
|
914
|
+
class="button ${(x) => classNames(
|
|
915
|
+
x._applyContrastClass(x._buttonColor) ? "contrast" : "",
|
|
916
|
+
x.disabled ? "disabled" : ""
|
|
917
|
+
)}"
|
|
918
|
+
style="--button-color: ${(x) => x._buttonColor};"
|
|
919
|
+
?disabled="${(x) => x.disabled}"
|
|
920
|
+
@click="${(x) => x._onButtonClick()}"
|
|
921
|
+
slot="action-items"
|
|
922
|
+
${ref("_buttonEl")}>
|
|
923
|
+
<${iconTag} name="edit-line"></${iconTag}>
|
|
924
|
+
</button>
|
|
925
|
+
<slot
|
|
926
|
+
slot="${(x) => x._helperTextSlottedContent?.length ? "helper-text" : void 0}"
|
|
927
|
+
name="helper-text"
|
|
928
|
+
${slotted("_helperTextSlottedContent")}
|
|
929
|
+
></slot>
|
|
930
|
+
<slot
|
|
931
|
+
slot='${(x) => x._contextualHelpSlottedContent?.length ? "contextual-help" : void 0}'
|
|
932
|
+
name='contextual-help'
|
|
933
|
+
${slotted("_contextualHelpSlottedContent")}
|
|
934
|
+
></slot>
|
|
935
|
+
</${textFieldTag}>
|
|
936
|
+
`;
|
|
937
|
+
}
|
|
938
|
+
function renderPopupHeader(buttonTag, iconTag) {
|
|
939
|
+
return html`
|
|
940
|
+
<div class="header">
|
|
941
|
+
<span class="header-title" id="color-picker-title">
|
|
942
|
+
<slot name="popup-text">${(x) => x.locale.colorPicker.popupLabel}</slot>
|
|
943
|
+
</span>
|
|
944
|
+
<${buttonTag} size="condensed"
|
|
945
|
+
aria-label="${(x) => x.locale.colorPicker.closeButtonLabel}"
|
|
946
|
+
@click="${(x) => x._handleCloseRequest()}">
|
|
947
|
+
<${iconTag} slot="icon" name="close-line"></${iconTag}>
|
|
948
|
+
</${buttonTag}>
|
|
949
|
+
</div>
|
|
950
|
+
`;
|
|
951
|
+
}
|
|
952
|
+
function renderPopupBody(buttonTag, iconTag) {
|
|
953
|
+
return html`
|
|
954
|
+
<div class="body">
|
|
955
|
+
<${html.partial(vcPickerTag)}
|
|
956
|
+
part="hex-picker"
|
|
957
|
+
color="${(x) => x.value}"
|
|
958
|
+
@color-changed="${(x, c) => x._onPickerColorChanged(c.event)}"
|
|
959
|
+
${ref("_vcHexPickerEl")}
|
|
960
|
+
></${html.partial(vcPickerTag)}>
|
|
961
|
+
<div class="hex-input-wrapper">
|
|
962
|
+
<${html.partial(vcInputTag)}
|
|
963
|
+
part="hex-input"
|
|
964
|
+
prefixed
|
|
965
|
+
color="${(x) => x.value}"
|
|
966
|
+
@color-changed="${(x, c) => x._onPickerColorChanged(c.event)}"
|
|
967
|
+
${ref("_vcHexInputEl")}
|
|
968
|
+
></${html.partial(vcInputTag)}>
|
|
969
|
+
<${buttonTag} size="normal"
|
|
970
|
+
aria-label="${(x) => x.locale.colorPicker.copyButtonLabel}"
|
|
971
|
+
@click="${(x) => x._copyValueToClipboard(x.value)}">
|
|
972
|
+
<${iconTag} slot="icon" name="${(x) => x.copyIconName}"></${iconTag}>
|
|
973
|
+
</${buttonTag}>
|
|
974
|
+
</div>
|
|
975
|
+
</div>
|
|
976
|
+
`;
|
|
977
|
+
}
|
|
978
|
+
function renderPopupFooter(buttonTag, iconTag) {
|
|
979
|
+
return html`
|
|
980
|
+
<div class="footer">
|
|
981
|
+
<span class="footer-title" id="color-picker-footer-title"
|
|
982
|
+
><slot name="swatches-text"
|
|
983
|
+
>${(x) => x.locale.colorPicker.swatchesLabel}</slot
|
|
984
|
+
></span
|
|
985
|
+
>
|
|
986
|
+
<div
|
|
987
|
+
class="palette"
|
|
988
|
+
role="grid"
|
|
989
|
+
aria-rowcount="${(x) => Math.ceil(x.allSwatches.length / x._getRowLength())}"
|
|
990
|
+
aria-colcount="${(x) => x._getRowLength()}"
|
|
991
|
+
style="--swatches-per-row: ${(x) => x._getRowLength()};"
|
|
992
|
+
aria-labelledby="color-picker-footer-title"
|
|
993
|
+
>
|
|
994
|
+
${repeat(
|
|
995
|
+
(x) => x.allSwatches,
|
|
996
|
+
(x) => x._renderColorSwatch(iconTag),
|
|
997
|
+
{ positioning: true }
|
|
998
|
+
)}
|
|
999
|
+
${when(
|
|
1000
|
+
(x) => !x.disableSavedColors,
|
|
1001
|
+
html`
|
|
1002
|
+
<${buttonTag}
|
|
1003
|
+
appearance="outlined"
|
|
1004
|
+
size="super-condensed"
|
|
1005
|
+
role="gridcell"
|
|
1006
|
+
tabindex="${(x) => x.allSwatches.length ? "-1" : "0"}"
|
|
1007
|
+
aria-label="${(x) => x.locale.colorPicker.saveButtonLabel}"
|
|
1008
|
+
@click="${(x) => x._saveCurrentColor()}"
|
|
1009
|
+
@keydown="${(x, c) => x._handleCellKeydown(
|
|
1010
|
+
c.event,
|
|
1011
|
+
x.value,
|
|
1012
|
+
x.allSwatches.length,
|
|
1013
|
+
true
|
|
1014
|
+
)}">
|
|
1015
|
+
>
|
|
1016
|
+
<${iconTag} slot="icon" name="plus-line"></${iconTag}>
|
|
1017
|
+
</${buttonTag}>
|
|
1018
|
+
`
|
|
1019
|
+
)}
|
|
1020
|
+
</div>
|
|
1021
|
+
</div>
|
|
1022
|
+
`;
|
|
1023
|
+
}
|
|
1024
|
+
const ColorPickerTemplate = (context) => {
|
|
1025
|
+
const textFieldTag = context.tagFor(TextField);
|
|
1026
|
+
const iconTag = context.tagFor(Icon);
|
|
1027
|
+
const popupTag = context.tagFor(Popup);
|
|
1028
|
+
const buttonTag = context.tagFor(Button);
|
|
1029
|
+
return html`
|
|
1030
|
+
<div class="base">
|
|
1031
|
+
${renderTextField(textFieldTag, iconTag)}
|
|
1032
|
+
<${popupTag}
|
|
1033
|
+
:open="${(x) => x.open}"
|
|
1034
|
+
:anchor="${(x) => x._buttonEl}"
|
|
1035
|
+
placement="top"
|
|
1036
|
+
offset="10"
|
|
1037
|
+
${ref("_popupEl")}>
|
|
1038
|
+
<div class="dialog"
|
|
1039
|
+
role="dialog"
|
|
1040
|
+
aria-modal="true"
|
|
1041
|
+
aria-labelledby="color-picker-title">
|
|
1042
|
+
${renderPopupHeader(buttonTag, iconTag)}
|
|
1043
|
+
${renderPopupBody(buttonTag, iconTag)}
|
|
1044
|
+
${when(
|
|
1045
|
+
(x) => !x.disableSavedColors || x.allSwatches.length > 0,
|
|
1046
|
+
renderPopupFooter(buttonTag, iconTag)
|
|
1047
|
+
)}
|
|
1048
|
+
</div>
|
|
1049
|
+
</${popupTag}>
|
|
1050
|
+
</div>
|
|
1051
|
+
`;
|
|
1052
|
+
};
|
|
1053
|
+
|
|
1054
|
+
const colorPickerDefinition = defineVividComponent(
|
|
1055
|
+
"color-picker",
|
|
1056
|
+
ColorPicker,
|
|
1057
|
+
ColorPickerTemplate,
|
|
1058
|
+
[
|
|
1059
|
+
popupDefinition,
|
|
1060
|
+
iconDefinition,
|
|
1061
|
+
textFieldDefinition,
|
|
1062
|
+
buttonDefinition,
|
|
1063
|
+
feedbackMessageDefinition
|
|
1064
|
+
],
|
|
1065
|
+
{
|
|
1066
|
+
styles
|
|
1067
|
+
}
|
|
1068
|
+
);
|
|
1069
|
+
const registerColorPicker = createRegisterFunction(
|
|
1070
|
+
colorPickerDefinition
|
|
1071
|
+
);
|
|
1072
|
+
|
|
1073
|
+
export { ColorPicker as VwcColorPickerElement, colorPickerDefinition, registerColorPicker };
|