@ckeditor/ckeditor5-ui 47.6.1 → 48.0.0-alpha.1
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/LICENSE.md +1 -1
- package/ckeditor5-metadata.json +3 -3
- package/{src → dist}/colorselector/documentcolorcollection.d.ts +4 -4
- package/{src → dist}/dialog/dialog.d.ts +1 -1
- package/dist/index-editor.css +2728 -587
- package/dist/index.css +2673 -850
- package/dist/index.css.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/{src → dist}/menubar/menubarmenuview.d.ts +4 -0
- package/{src → dist}/view.d.ts +1 -1
- package/package.json +25 -47
- package/lang/contexts.json +0 -51
- package/lang/translations/af.po +0 -208
- package/lang/translations/ar.po +0 -208
- package/lang/translations/ast.po +0 -208
- package/lang/translations/az.po +0 -208
- package/lang/translations/be.po +0 -208
- package/lang/translations/bg.po +0 -208
- package/lang/translations/bn.po +0 -208
- package/lang/translations/bs.po +0 -208
- package/lang/translations/ca.po +0 -208
- package/lang/translations/cs.po +0 -208
- package/lang/translations/da.po +0 -208
- package/lang/translations/de-ch.po +0 -208
- package/lang/translations/de.po +0 -208
- package/lang/translations/el.po +0 -208
- package/lang/translations/en-au.po +0 -208
- package/lang/translations/en-gb.po +0 -208
- package/lang/translations/en.po +0 -208
- package/lang/translations/eo.po +0 -208
- package/lang/translations/es-co.po +0 -208
- package/lang/translations/es.po +0 -208
- package/lang/translations/et.po +0 -208
- package/lang/translations/eu.po +0 -208
- package/lang/translations/fa.po +0 -208
- package/lang/translations/fi.po +0 -208
- package/lang/translations/fr.po +0 -208
- package/lang/translations/gl.po +0 -208
- package/lang/translations/gu.po +0 -208
- package/lang/translations/he.po +0 -208
- package/lang/translations/hi.po +0 -208
- package/lang/translations/hr.po +0 -208
- package/lang/translations/hu.po +0 -208
- package/lang/translations/hy.po +0 -208
- package/lang/translations/id.po +0 -208
- package/lang/translations/it.po +0 -208
- package/lang/translations/ja.po +0 -208
- package/lang/translations/jv.po +0 -208
- package/lang/translations/kk.po +0 -208
- package/lang/translations/km.po +0 -208
- package/lang/translations/kn.po +0 -208
- package/lang/translations/ko.po +0 -208
- package/lang/translations/ku.po +0 -208
- package/lang/translations/lt.po +0 -208
- package/lang/translations/lv.po +0 -208
- package/lang/translations/ms.po +0 -208
- package/lang/translations/nb.po +0 -208
- package/lang/translations/ne.po +0 -208
- package/lang/translations/nl.po +0 -208
- package/lang/translations/no.po +0 -208
- package/lang/translations/oc.po +0 -208
- package/lang/translations/pl.po +0 -208
- package/lang/translations/pt-br.po +0 -208
- package/lang/translations/pt.po +0 -208
- package/lang/translations/ro.po +0 -208
- package/lang/translations/ru.po +0 -208
- package/lang/translations/si.po +0 -208
- package/lang/translations/sk.po +0 -208
- package/lang/translations/sl.po +0 -208
- package/lang/translations/sq.po +0 -208
- package/lang/translations/sr-latn.po +0 -208
- package/lang/translations/sr.po +0 -208
- package/lang/translations/sv.po +0 -208
- package/lang/translations/th.po +0 -208
- package/lang/translations/ti.po +0 -208
- package/lang/translations/tk.po +0 -208
- package/lang/translations/tr.po +0 -208
- package/lang/translations/tt.po +0 -208
- package/lang/translations/ug.po +0 -208
- package/lang/translations/uk.po +0 -208
- package/lang/translations/ur.po +0 -208
- package/lang/translations/uz.po +0 -208
- package/lang/translations/vi.po +0 -208
- package/lang/translations/zh-cn.po +0 -208
- package/lang/translations/zh.po +0 -208
- package/src/arialiveannouncer.js +0 -189
- package/src/augmentation.js +0 -5
- package/src/autocomplete/autocompleteview.js +0 -157
- package/src/badge/badge.js +0 -226
- package/src/bindings/addkeyboardhandlingforgrid.js +0 -107
- package/src/bindings/clickoutsidehandler.js +0 -36
- package/src/bindings/csstransitiondisablermixin.js +0 -58
- package/src/bindings/draggableviewmixin.js +0 -144
- package/src/bindings/preventdefault.js +0 -35
- package/src/bindings/submithandler.js +0 -47
- package/src/button/button.js +0 -5
- package/src/button/buttonlabel.js +0 -5
- package/src/button/buttonlabelview.js +0 -42
- package/src/button/buttonview.js +0 -278
- package/src/button/filedialogbuttonview.js +0 -147
- package/src/button/listitembuttonview.js +0 -136
- package/src/button/switchbuttonview.js +0 -79
- package/src/collapsible/collapsibleview.js +0 -106
- package/src/colorgrid/colorgridview.js +0 -140
- package/src/colorgrid/colortileview.js +0 -42
- package/src/colorgrid/utils.js +0 -84
- package/src/colorpicker/colorpickerview.js +0 -356
- package/src/colorpicker/utils.js +0 -108
- package/src/colorselector/colorgridsfragmentview.js +0 -368
- package/src/colorselector/colorpickerfragmentview.js +0 -254
- package/src/colorselector/colorselectorview.js +0 -294
- package/src/colorselector/documentcolorcollection.js +0 -42
- package/src/componentfactory.js +0 -108
- package/src/dialog/dialog.js +0 -325
- package/src/dialog/dialogactionsview.js +0 -118
- package/src/dialog/dialogcontentview.js +0 -39
- package/src/dialog/dialogview.js +0 -507
- package/src/dropdown/button/dropdownbutton.js +0 -5
- package/src/dropdown/button/dropdownbuttonview.js +0 -70
- package/src/dropdown/button/splitbuttonview.js +0 -178
- package/src/dropdown/dropdownpanelfocusable.js +0 -5
- package/src/dropdown/dropdownpanelview.js +0 -106
- package/src/dropdown/dropdownview.js +0 -438
- package/src/dropdown/menu/dropdownmenubehaviors.js +0 -125
- package/src/dropdown/menu/dropdownmenubuttonview.js +0 -69
- package/src/dropdown/menu/dropdownmenulistitembuttonview.js +0 -30
- package/src/dropdown/menu/dropdownmenulistitemview.js +0 -38
- package/src/dropdown/menu/dropdownmenulistview.js +0 -29
- package/src/dropdown/menu/dropdownmenunestedmenupanelview.js +0 -63
- package/src/dropdown/menu/dropdownmenunestedmenuview.js +0 -214
- package/src/dropdown/menu/dropdownmenurootlistview.js +0 -168
- package/src/dropdown/menu/utils.js +0 -61
- package/src/dropdown/utils.js +0 -654
- package/src/editableui/editableuiview.js +0 -130
- package/src/editableui/inline/inlineeditableuiview.js +0 -75
- package/src/editorui/accessibilityhelp/accessibilityhelp.js +0 -142
- package/src/editorui/accessibilityhelp/accessibilityhelpcontentview.js +0 -112
- package/src/editorui/bodycollection.js +0 -128
- package/src/editorui/boxed/boxededitoruiview.js +0 -95
- package/src/editorui/editorui.js +0 -586
- package/src/editorui/editoruiview.js +0 -60
- package/src/editorui/evaluationbadge.js +0 -99
- package/src/editorui/poweredby.js +0 -120
- package/src/focuscycler.js +0 -383
- package/src/formheader/formheaderview.js +0 -77
- package/src/formrow/formrowview.js +0 -56
- package/src/highlightedtext/buttonlabelwithhighlightview.js +0 -31
- package/src/highlightedtext/highlightedtextview.js +0 -102
- package/src/highlightedtext/labelwithhighlightview.js +0 -37
- package/src/icon/iconview.js +0 -123
- package/src/iframe/iframeview.js +0 -63
- package/src/index.js +0 -132
- package/src/input/inputbase.js +0 -119
- package/src/input/inputview.js +0 -24
- package/src/inputnumber/inputnumberview.js +0 -40
- package/src/inputtext/inputtextview.js +0 -27
- package/src/label/labelview.js +0 -46
- package/src/labeledfield/labeledfieldview.js +0 -177
- package/src/labeledfield/utils.js +0 -176
- package/src/labeledinput/labeledinputview.js +0 -138
- package/src/legacyerrors.js +0 -20
- package/src/list/listitemgroupview.js +0 -82
- package/src/list/listitemview.js +0 -46
- package/src/list/listseparatorview.js +0 -28
- package/src/list/listview.js +0 -210
- package/src/menubar/menubarmenubuttonview.js +0 -68
- package/src/menubar/menubarmenulistitembuttonview.js +0 -30
- package/src/menubar/menubarmenulistitemfiledialogbuttonview.js +0 -32
- package/src/menubar/menubarmenulistitemview.js +0 -34
- package/src/menubar/menubarmenulistview.js +0 -72
- package/src/menubar/menubarmenupanelview.js +0 -64
- package/src/menubar/menubarmenuview.js +0 -198
- package/src/menubar/menubarview.js +0 -281
- package/src/menubar/utils.js +0 -1432
- package/src/model.js +0 -31
- package/src/notification/notification.js +0 -192
- package/src/panel/balloon/balloonpanelview.js +0 -1077
- package/src/panel/balloon/contextualballoon.js +0 -616
- package/src/panel/sticky/stickypanelview.js +0 -246
- package/src/search/filteredview.js +0 -5
- package/src/search/filtergroupanditemnames.js +0 -38
- package/src/search/searchinfoview.js +0 -59
- package/src/search/searchresultsview.js +0 -83
- package/src/search/text/searchtextqueryview.js +0 -87
- package/src/search/text/searchtextview.js +0 -242
- package/src/spinner/spinnerview.js +0 -38
- package/src/template.js +0 -1396
- package/src/textarea/textareaview.js +0 -189
- package/src/toolbar/balloon/balloontoolbar.js +0 -358
- package/src/toolbar/block/blockbuttonview.js +0 -41
- package/src/toolbar/block/blocktoolbar.js +0 -507
- package/src/toolbar/normalizetoolbarconfig.js +0 -52
- package/src/toolbar/toolbarlinebreakview.js +0 -28
- package/src/toolbar/toolbarseparatorview.js +0 -28
- package/src/toolbar/toolbarview.js +0 -873
- package/src/tooltipmanager.js +0 -454
- package/src/view.js +0 -471
- package/src/viewcollection.js +0 -210
- package/theme/components/arialiveannouncer/arialiveannouncer.css +0 -14
- package/theme/components/autocomplete/autocomplete.css +0 -22
- package/theme/components/button/button.css +0 -39
- package/theme/components/button/listitembutton.css +0 -48
- package/theme/components/button/switchbutton.css +0 -14
- package/theme/components/collapsible/collapsible.css +0 -10
- package/theme/components/colorgrid/colorgrid.css +0 -8
- package/theme/components/colorpicker/colorpicker.css +0 -34
- package/theme/components/colorselector/colorselector.css +0 -35
- package/theme/components/dialog/dialog.css +0 -42
- package/theme/components/dialog/dialogactions.css +0 -11
- package/theme/components/dropdown/dropdown.css +0 -95
- package/theme/components/dropdown/listdropdown.css +0 -10
- package/theme/components/dropdown/menu/dropdownmenu.css +0 -8
- package/theme/components/dropdown/menu/dropdownmenubutton.css +0 -9
- package/theme/components/dropdown/menu/dropdownmenulistitem.css +0 -10
- package/theme/components/dropdown/menu/dropdownmenulistitembutton.css +0 -10
- package/theme/components/dropdown/menu/dropdownmenupanel.css +0 -11
- package/theme/components/dropdown/splitbutton.css +0 -14
- package/theme/components/dropdown/toolbardropdown.css +0 -20
- package/theme/components/editorui/accessibilityhelp.css +0 -10
- package/theme/components/editorui/editorui.css +0 -10
- package/theme/components/form/form.css +0 -87
- package/theme/components/formheader/formheader.css +0 -18
- package/theme/components/formrow/formrow.css +0 -32
- package/theme/components/highlightedtext/highlightedtext.css +0 -12
- package/theme/components/icon/icon.css +0 -8
- package/theme/components/input/input.css +0 -10
- package/theme/components/label/label.css +0 -12
- package/theme/components/labeledfield/labeledfieldview.css +0 -16
- package/theme/components/labeledinput/labeledinput.css +0 -10
- package/theme/components/list/list.css +0 -26
- package/theme/components/menubar/menubar.css +0 -10
- package/theme/components/menubar/menubarmenu.css +0 -9
- package/theme/components/menubar/menubarmenubutton.css +0 -11
- package/theme/components/menubar/menubarmenulistitem.css +0 -10
- package/theme/components/menubar/menubarmenulistitembutton.css +0 -10
- package/theme/components/menubar/menubarmenupanel.css +0 -62
- package/theme/components/panel/balloonpanel.css +0 -56
- package/theme/components/panel/balloonrotator.css +0 -17
- package/theme/components/panel/fakepanel.css +0 -23
- package/theme/components/panel/stickypanel.css +0 -17
- package/theme/components/responsive-form/responsiveform.css +0 -42
- package/theme/components/search/search.css +0 -43
- package/theme/components/spinner/spinner.css +0 -23
- package/theme/components/textarea/textarea.css +0 -10
- package/theme/components/toolbar/blocktoolbar.css +0 -9
- package/theme/components/toolbar/toolbar.css +0 -58
- package/theme/components/tooltip/tooltip.css +0 -12
- package/theme/globals/_evaluationbadge.css +0 -54
- package/theme/globals/_hidden.css +0 -13
- package/theme/globals/_poweredby.css +0 -84
- package/theme/globals/_transition.css +0 -12
- package/theme/globals/_zindex.css +0 -10
- package/theme/globals/globals.css +0 -10
- package/theme/mixins/_dir.css +0 -10
- package/theme/mixins/_mediacolors.css +0 -20
- package/theme/mixins/_rwd.css +0 -10
- package/theme/mixins/_unselectable.css +0 -14
- /package/{src → dist}/arialiveannouncer.d.ts +0 -0
- /package/{src → dist}/augmentation.d.ts +0 -0
- /package/{src → dist}/autocomplete/autocompleteview.d.ts +0 -0
- /package/{src → dist}/badge/badge.d.ts +0 -0
- /package/{src → dist}/bindings/addkeyboardhandlingforgrid.d.ts +0 -0
- /package/{src → dist}/bindings/clickoutsidehandler.d.ts +0 -0
- /package/{src → dist}/bindings/csstransitiondisablermixin.d.ts +0 -0
- /package/{src → dist}/bindings/draggableviewmixin.d.ts +0 -0
- /package/{src → dist}/bindings/preventdefault.d.ts +0 -0
- /package/{src → dist}/bindings/submithandler.d.ts +0 -0
- /package/{src → dist}/button/button.d.ts +0 -0
- /package/{src → dist}/button/buttonlabel.d.ts +0 -0
- /package/{src → dist}/button/buttonlabelview.d.ts +0 -0
- /package/{src → dist}/button/buttonview.d.ts +0 -0
- /package/{src → dist}/button/filedialogbuttonview.d.ts +0 -0
- /package/{src → dist}/button/listitembuttonview.d.ts +0 -0
- /package/{src → dist}/button/switchbuttonview.d.ts +0 -0
- /package/{src → dist}/collapsible/collapsibleview.d.ts +0 -0
- /package/{src → dist}/colorgrid/colorgridview.d.ts +0 -0
- /package/{src → dist}/colorgrid/colortileview.d.ts +0 -0
- /package/{src → dist}/colorgrid/utils.d.ts +0 -0
- /package/{src → dist}/colorpicker/colorpickerview.d.ts +0 -0
- /package/{src → dist}/colorpicker/utils.d.ts +0 -0
- /package/{src → dist}/colorselector/colorgridsfragmentview.d.ts +0 -0
- /package/{src → dist}/colorselector/colorpickerfragmentview.d.ts +0 -0
- /package/{src → dist}/colorselector/colorselectorview.d.ts +0 -0
- /package/{src → dist}/componentfactory.d.ts +0 -0
- /package/{src → dist}/dialog/dialogactionsview.d.ts +0 -0
- /package/{src → dist}/dialog/dialogcontentview.d.ts +0 -0
- /package/{src → dist}/dialog/dialogview.d.ts +0 -0
- /package/{src → dist}/dropdown/button/dropdownbutton.d.ts +0 -0
- /package/{src → dist}/dropdown/button/dropdownbuttonview.d.ts +0 -0
- /package/{src → dist}/dropdown/button/splitbuttonview.d.ts +0 -0
- /package/{src → dist}/dropdown/dropdownpanelfocusable.d.ts +0 -0
- /package/{src → dist}/dropdown/dropdownpanelview.d.ts +0 -0
- /package/{src → dist}/dropdown/dropdownview.d.ts +0 -0
- /package/{src → dist}/dropdown/menu/dropdownmenubehaviors.d.ts +0 -0
- /package/{src → dist}/dropdown/menu/dropdownmenubuttonview.d.ts +0 -0
- /package/{src → dist}/dropdown/menu/dropdownmenulistitembuttonview.d.ts +0 -0
- /package/{src → dist}/dropdown/menu/dropdownmenulistitemview.d.ts +0 -0
- /package/{src → dist}/dropdown/menu/dropdownmenulistview.d.ts +0 -0
- /package/{src → dist}/dropdown/menu/dropdownmenunestedmenupanelview.d.ts +0 -0
- /package/{src → dist}/dropdown/menu/dropdownmenunestedmenuview.d.ts +0 -0
- /package/{src → dist}/dropdown/menu/dropdownmenurootlistview.d.ts +0 -0
- /package/{src → dist}/dropdown/menu/utils.d.ts +0 -0
- /package/{src → dist}/dropdown/utils.d.ts +0 -0
- /package/{src → dist}/editableui/editableuiview.d.ts +0 -0
- /package/{src → dist}/editableui/inline/inlineeditableuiview.d.ts +0 -0
- /package/{src → dist}/editorui/accessibilityhelp/accessibilityhelp.d.ts +0 -0
- /package/{src → dist}/editorui/accessibilityhelp/accessibilityhelpcontentview.d.ts +0 -0
- /package/{src → dist}/editorui/bodycollection.d.ts +0 -0
- /package/{src → dist}/editorui/boxed/boxededitoruiview.d.ts +0 -0
- /package/{src → dist}/editorui/editorui.d.ts +0 -0
- /package/{src → dist}/editorui/editoruiview.d.ts +0 -0
- /package/{src → dist}/editorui/evaluationbadge.d.ts +0 -0
- /package/{src → dist}/editorui/poweredby.d.ts +0 -0
- /package/{src → dist}/focuscycler.d.ts +0 -0
- /package/{src → dist}/formheader/formheaderview.d.ts +0 -0
- /package/{src → dist}/formrow/formrowview.d.ts +0 -0
- /package/{src → dist}/highlightedtext/buttonlabelwithhighlightview.d.ts +0 -0
- /package/{src → dist}/highlightedtext/highlightedtextview.d.ts +0 -0
- /package/{src → dist}/highlightedtext/labelwithhighlightview.d.ts +0 -0
- /package/{src → dist}/icon/iconview.d.ts +0 -0
- /package/{src → dist}/iframe/iframeview.d.ts +0 -0
- /package/{src → dist}/index.d.ts +0 -0
- /package/{src → dist}/input/inputbase.d.ts +0 -0
- /package/{src → dist}/input/inputview.d.ts +0 -0
- /package/{src → dist}/inputnumber/inputnumberview.d.ts +0 -0
- /package/{src → dist}/inputtext/inputtextview.d.ts +0 -0
- /package/{src → dist}/label/labelview.d.ts +0 -0
- /package/{src → dist}/labeledfield/labeledfieldview.d.ts +0 -0
- /package/{src → dist}/labeledfield/utils.d.ts +0 -0
- /package/{src → dist}/labeledinput/labeledinputview.d.ts +0 -0
- /package/{src → dist}/legacyerrors.d.ts +0 -0
- /package/{src → dist}/list/listitemgroupview.d.ts +0 -0
- /package/{src → dist}/list/listitemview.d.ts +0 -0
- /package/{src → dist}/list/listseparatorview.d.ts +0 -0
- /package/{src → dist}/list/listview.d.ts +0 -0
- /package/{src → dist}/menubar/menubarmenubuttonview.d.ts +0 -0
- /package/{src → dist}/menubar/menubarmenulistitembuttonview.d.ts +0 -0
- /package/{src → dist}/menubar/menubarmenulistitemfiledialogbuttonview.d.ts +0 -0
- /package/{src → dist}/menubar/menubarmenulistitemview.d.ts +0 -0
- /package/{src → dist}/menubar/menubarmenulistview.d.ts +0 -0
- /package/{src → dist}/menubar/menubarmenupanelview.d.ts +0 -0
- /package/{src → dist}/menubar/menubarview.d.ts +0 -0
- /package/{src → dist}/menubar/utils.d.ts +0 -0
- /package/{src → dist}/model.d.ts +0 -0
- /package/{src → dist}/notification/notification.d.ts +0 -0
- /package/{src → dist}/panel/balloon/balloonpanelview.d.ts +0 -0
- /package/{src → dist}/panel/balloon/contextualballoon.d.ts +0 -0
- /package/{src → dist}/panel/sticky/stickypanelview.d.ts +0 -0
- /package/{src → dist}/search/filteredview.d.ts +0 -0
- /package/{src → dist}/search/filtergroupanditemnames.d.ts +0 -0
- /package/{src → dist}/search/searchinfoview.d.ts +0 -0
- /package/{src → dist}/search/searchresultsview.d.ts +0 -0
- /package/{src → dist}/search/text/searchtextqueryview.d.ts +0 -0
- /package/{src → dist}/search/text/searchtextview.d.ts +0 -0
- /package/{src → dist}/spinner/spinnerview.d.ts +0 -0
- /package/{src → dist}/template.d.ts +0 -0
- /package/{src → dist}/textarea/textareaview.d.ts +0 -0
- /package/{src → dist}/toolbar/balloon/balloontoolbar.d.ts +0 -0
- /package/{src → dist}/toolbar/block/blockbuttonview.d.ts +0 -0
- /package/{src → dist}/toolbar/block/blocktoolbar.d.ts +0 -0
- /package/{src → dist}/toolbar/normalizetoolbarconfig.d.ts +0 -0
- /package/{src → dist}/toolbar/toolbarlinebreakview.d.ts +0 -0
- /package/{src → dist}/toolbar/toolbarseparatorview.d.ts +0 -0
- /package/{src → dist}/toolbar/toolbarview.d.ts +0 -0
- /package/{src → dist}/tooltipmanager.d.ts +0 -0
- /package/{src → dist}/viewcollection.d.ts +0 -0
package/src/colorgrid/utils.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Returns color configuration options as defined in `editor.config.(fontColor|fontBackgroundColor).colors` or
|
|
7
|
-
* `editor.config.table.(tableProperties|tableCellProperties).(background|border).colors
|
|
8
|
-
* but processed to account for editor localization in the correct language.
|
|
9
|
-
*
|
|
10
|
-
* Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
|
|
11
|
-
* when the user configuration is defined because the editor does not exist yet.
|
|
12
|
-
*
|
|
13
|
-
* @param locale The {@link module:core/editor/editor~Editor#locale} instance.
|
|
14
|
-
*/
|
|
15
|
-
export function getLocalizedColorOptions(locale, options) {
|
|
16
|
-
const t = locale.t;
|
|
17
|
-
const localizedColorNames = {
|
|
18
|
-
Black: t('Black'),
|
|
19
|
-
'Dim grey': t('Dim grey'),
|
|
20
|
-
Grey: t('Grey'),
|
|
21
|
-
'Light grey': t('Light grey'),
|
|
22
|
-
White: t('White'),
|
|
23
|
-
Red: t('Red'),
|
|
24
|
-
Orange: t('Orange'),
|
|
25
|
-
Yellow: t('Yellow'),
|
|
26
|
-
'Light green': t('Light green'),
|
|
27
|
-
Green: t('Green'),
|
|
28
|
-
Aquamarine: t('Aquamarine'),
|
|
29
|
-
Turquoise: t('Turquoise'),
|
|
30
|
-
'Light blue': t('Light blue'),
|
|
31
|
-
Blue: t('Blue'),
|
|
32
|
-
Purple: t('Purple')
|
|
33
|
-
};
|
|
34
|
-
return options.map(colorOption => {
|
|
35
|
-
const label = localizedColorNames[colorOption.label];
|
|
36
|
-
if (label && label != colorOption.label) {
|
|
37
|
-
colorOption.label = label;
|
|
38
|
-
}
|
|
39
|
-
return colorOption;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Creates a unified color definition object from color configuration options.
|
|
44
|
-
* The object contains the information necessary to both render the UI and initialize the conversion.
|
|
45
|
-
*/
|
|
46
|
-
export function normalizeColorOptions(options) {
|
|
47
|
-
return options
|
|
48
|
-
.map(normalizeSingleColorDefinition)
|
|
49
|
-
.filter(option => !!option);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Creates a normalized color definition from the user-defined configuration.
|
|
53
|
-
* The "normalization" means it will create full
|
|
54
|
-
* {@link module:ui/colorgrid/colorgridview~ColorDefinition `ColorDefinition-like`}
|
|
55
|
-
* object for string values, and add a `view` property, for each definition.
|
|
56
|
-
*/
|
|
57
|
-
export function normalizeSingleColorDefinition(color) {
|
|
58
|
-
if (typeof color === 'string') {
|
|
59
|
-
return {
|
|
60
|
-
model: color,
|
|
61
|
-
label: color,
|
|
62
|
-
hasBorder: false,
|
|
63
|
-
view: {
|
|
64
|
-
name: 'span',
|
|
65
|
-
styles: {
|
|
66
|
-
color
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
return {
|
|
73
|
-
model: color.color,
|
|
74
|
-
label: color.label || color.color,
|
|
75
|
-
hasBorder: color.hasBorder === undefined ? false : color.hasBorder,
|
|
76
|
-
view: {
|
|
77
|
-
name: 'span',
|
|
78
|
-
styles: {
|
|
79
|
-
color: `${color.color}`
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
}
|
|
@@ -1,356 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module ui/colorpicker/colorpickerview
|
|
7
|
-
*/
|
|
8
|
-
import { convertColor, convertToHex, registerCustomElement } from './utils.js';
|
|
9
|
-
import { global, env } from '@ckeditor/ckeditor5-utils';
|
|
10
|
-
import { debounce } from 'es-toolkit/compat';
|
|
11
|
-
import { View } from '../view.js';
|
|
12
|
-
import { LabeledFieldView } from '../labeledfield/labeledfieldview.js';
|
|
13
|
-
import { createLabeledInputText } from '../labeledfield/utils.js';
|
|
14
|
-
// Custom export due to https://github.com/ckeditor/ckeditor5/issues/15698.
|
|
15
|
-
import { HexBase } from 'vanilla-colorful/lib/entrypoints/hex';
|
|
16
|
-
import '../../theme/components/colorpicker/colorpicker.css';
|
|
17
|
-
const waitingTime = 150;
|
|
18
|
-
/**
|
|
19
|
-
* A class which represents a color picker with an input field for defining custom colors.
|
|
20
|
-
*/
|
|
21
|
-
export class ColorPickerView extends View {
|
|
22
|
-
/**
|
|
23
|
-
* Container for a `#` sign prefix and an input for displaying and defining custom colors
|
|
24
|
-
* in HEX format.
|
|
25
|
-
*/
|
|
26
|
-
hexInputRow;
|
|
27
|
-
/**
|
|
28
|
-
* Debounced function updating the `color` property in the component
|
|
29
|
-
* and firing the `ColorPickerColorSelectedEvent`. Executed whenever color in component
|
|
30
|
-
* is changed by the user interaction (through the palette or input).
|
|
31
|
-
*
|
|
32
|
-
* @private
|
|
33
|
-
*/
|
|
34
|
-
_debounceColorPickerEvent;
|
|
35
|
-
/**
|
|
36
|
-
* A reference to the configuration of the color picker specified in the constructor.
|
|
37
|
-
*
|
|
38
|
-
* @private
|
|
39
|
-
*/
|
|
40
|
-
_config;
|
|
41
|
-
/**
|
|
42
|
-
* Creates a view of color picker.
|
|
43
|
-
*
|
|
44
|
-
* @param locale
|
|
45
|
-
* @param config
|
|
46
|
-
*/
|
|
47
|
-
constructor(locale, config = {}) {
|
|
48
|
-
super(locale);
|
|
49
|
-
this.set({
|
|
50
|
-
color: '',
|
|
51
|
-
_hexColor: ''
|
|
52
|
-
});
|
|
53
|
-
this.hexInputRow = this._createInputRow();
|
|
54
|
-
const children = this.createCollection();
|
|
55
|
-
if (!config.hideInput) {
|
|
56
|
-
children.add(this.hexInputRow);
|
|
57
|
-
}
|
|
58
|
-
this.setTemplate({
|
|
59
|
-
tag: 'div',
|
|
60
|
-
attributes: {
|
|
61
|
-
class: ['ck', 'ck-color-picker'],
|
|
62
|
-
tabindex: -1
|
|
63
|
-
},
|
|
64
|
-
children
|
|
65
|
-
});
|
|
66
|
-
this._config = config;
|
|
67
|
-
this._debounceColorPickerEvent = debounce((color) => {
|
|
68
|
-
// At first, set the color internally in the component. It's converted to the configured output format.
|
|
69
|
-
this.set('color', color);
|
|
70
|
-
// Then let the outside world know that the user changed the color.
|
|
71
|
-
this.fire('colorSelected', { color: this.color });
|
|
72
|
-
}, waitingTime, {
|
|
73
|
-
leading: true
|
|
74
|
-
});
|
|
75
|
-
// The `color` property holds the color in the configured output format.
|
|
76
|
-
// Ensure it before actually setting the value.
|
|
77
|
-
this.on('set:color', (evt, propertyName, newValue) => {
|
|
78
|
-
evt.return = convertColor(newValue, this._config.format || 'hsl');
|
|
79
|
-
});
|
|
80
|
-
// The `_hexColor` property is bound to the `color` one, but requires conversion.
|
|
81
|
-
this.on('change:color', () => {
|
|
82
|
-
this._hexColor = convertColorToCommonHexFormat(this.color);
|
|
83
|
-
});
|
|
84
|
-
this.on('change:_hexColor', () => {
|
|
85
|
-
// Update the selected color in the color picker palette when it's not focused.
|
|
86
|
-
// It means the user typed the color in the input.
|
|
87
|
-
if (document.activeElement !== this.picker) {
|
|
88
|
-
this.picker.setAttribute('color', this._hexColor);
|
|
89
|
-
}
|
|
90
|
-
// There has to be two way binding between properties.
|
|
91
|
-
// Extra precaution has to be taken to trigger change back only when the color really changes.
|
|
92
|
-
if (convertColorToCommonHexFormat(this.color) != convertColorToCommonHexFormat(this._hexColor)) {
|
|
93
|
-
this.color = this._hexColor;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Renders color picker in the view.
|
|
99
|
-
*/
|
|
100
|
-
render() {
|
|
101
|
-
super.render();
|
|
102
|
-
// Extracted to the helper to make it testable.
|
|
103
|
-
registerCustomElement('hex-color-picker', HexBase);
|
|
104
|
-
this.picker = global.document.createElement('hex-color-picker');
|
|
105
|
-
this.picker.setAttribute('class', 'hex-color-picker');
|
|
106
|
-
this.picker.setAttribute('tabindex', '-1');
|
|
107
|
-
this._createSlidersView();
|
|
108
|
-
if (this.element) {
|
|
109
|
-
if (this.hexInputRow.element) {
|
|
110
|
-
this.element.insertBefore(this.picker, this.hexInputRow.element);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
this.element.appendChild(this.picker);
|
|
114
|
-
}
|
|
115
|
-
// Create custom stylesheet with a look of focused pointer in color picker and append it into the color picker shadowDom
|
|
116
|
-
const styleSheetForFocusedColorPicker = document.createElement('style');
|
|
117
|
-
styleSheetForFocusedColorPicker.textContent = '[role="slider"]:focus [part$="pointer"] {' +
|
|
118
|
-
'border: 1px solid #fff;' +
|
|
119
|
-
'outline: 1px solid var(--ck-color-focus-border);' +
|
|
120
|
-
'box-shadow: 0 0 0 2px #fff;' +
|
|
121
|
-
'}';
|
|
122
|
-
this.picker.shadowRoot.appendChild(styleSheetForFocusedColorPicker);
|
|
123
|
-
}
|
|
124
|
-
this.picker.addEventListener('color-changed', event => {
|
|
125
|
-
const color = event.detail.value;
|
|
126
|
-
this._debounceColorPickerEvent(color);
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Focuses the first pointer in color picker.
|
|
131
|
-
*
|
|
132
|
-
*/
|
|
133
|
-
focus() {
|
|
134
|
-
// In some browsers we need to move the focus to the input first.
|
|
135
|
-
// Otherwise, the color picker doesn't behave as expected.
|
|
136
|
-
// In Chrome, after selecting the color via slider the first time,
|
|
137
|
-
// the editor collapses the selection and doesn't apply the color change.
|
|
138
|
-
// In FF, after selecting the color via slider, it instantly moves back to the previous color.
|
|
139
|
-
// In all iOS browsers and desktop Safari, once the saturation slider is moved for the first time,
|
|
140
|
-
// editor collapses the selection and doesn't apply the color change.
|
|
141
|
-
// See: https://github.com/ckeditor/ckeditor5-internal/issues/3245, https://github.com/ckeditor/ckeditor5/issues/14119,
|
|
142
|
-
// https://github.com/ckeditor/ckeditor5-internal/issues/3268.
|
|
143
|
-
/* istanbul ignore next -- @preserve */
|
|
144
|
-
if (!this._config.hideInput && (env.isGecko || env.isiOS || env.isSafari || env.isBlink)) {
|
|
145
|
-
const input = this.hexInputRow.children.get(1);
|
|
146
|
-
input.focus();
|
|
147
|
-
}
|
|
148
|
-
const firstSlider = this.slidersView.first;
|
|
149
|
-
firstSlider.focus();
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Creates collection of sliders in color picker.
|
|
153
|
-
*
|
|
154
|
-
* @private
|
|
155
|
-
*/
|
|
156
|
-
_createSlidersView() {
|
|
157
|
-
const colorPickersChildren = [...this.picker.shadowRoot.children];
|
|
158
|
-
const sliders = colorPickersChildren.filter(item => item.getAttribute('role') === 'slider');
|
|
159
|
-
const slidersView = sliders.map(slider => {
|
|
160
|
-
const view = new SliderView(slider);
|
|
161
|
-
return view;
|
|
162
|
-
});
|
|
163
|
-
this.slidersView = this.createCollection();
|
|
164
|
-
slidersView.forEach(item => {
|
|
165
|
-
this.slidersView.add(item);
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Creates input row for defining custom colors in color picker.
|
|
170
|
-
*
|
|
171
|
-
* @private
|
|
172
|
-
*/
|
|
173
|
-
_createInputRow() {
|
|
174
|
-
const colorInput = this._createColorInput();
|
|
175
|
-
return new ColorPickerInputRowView(this.locale, colorInput);
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Creates the input where user can type or paste the color in hex format.
|
|
179
|
-
*
|
|
180
|
-
* @private
|
|
181
|
-
*/
|
|
182
|
-
_createColorInput() {
|
|
183
|
-
const labeledInput = new LabeledFieldView(this.locale, createLabeledInputText);
|
|
184
|
-
const { t } = this.locale;
|
|
185
|
-
labeledInput.set({
|
|
186
|
-
label: t('HEX'),
|
|
187
|
-
class: 'color-picker-hex-input'
|
|
188
|
-
});
|
|
189
|
-
labeledInput.fieldView.bind('value').to(this, '_hexColor', pickerColor => {
|
|
190
|
-
if (labeledInput.isFocused) {
|
|
191
|
-
// Text field shouldn't be updated with color change if the text field is focused.
|
|
192
|
-
// Imagine user typing hex code and getting the value of field changed.
|
|
193
|
-
return labeledInput.fieldView.value;
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
return pickerColor.startsWith('#') ? pickerColor.substring(1) : pickerColor;
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
// Only accept valid hex colors as input.
|
|
200
|
-
labeledInput.fieldView.on('input', () => {
|
|
201
|
-
const inputValue = labeledInput.fieldView.element.value;
|
|
202
|
-
if (inputValue) {
|
|
203
|
-
const maybeHexColor = tryParseHexColor(inputValue);
|
|
204
|
-
if (maybeHexColor) {
|
|
205
|
-
// If so, set the color.
|
|
206
|
-
// Otherwise, do nothing.
|
|
207
|
-
this._debounceColorPickerEvent(maybeHexColor);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
return labeledInput;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Validates the view and returns `false` when some fields are invalid.
|
|
215
|
-
*/
|
|
216
|
-
isValid() {
|
|
217
|
-
const { t } = this.locale;
|
|
218
|
-
// If the input is hidden, it's always valid, because there is no way to select
|
|
219
|
-
// invalid color value using diagram color picker.
|
|
220
|
-
if (this._config.hideInput) {
|
|
221
|
-
return true;
|
|
222
|
-
}
|
|
223
|
-
this.resetValidationStatus();
|
|
224
|
-
// One error per field is enough.
|
|
225
|
-
if (!this.hexInputRow.getParsedColor()) {
|
|
226
|
-
// Apply updated error.
|
|
227
|
-
this.hexInputRow.inputView.errorText = t('Please enter a valid color (e.g. "ff0000").');
|
|
228
|
-
return false;
|
|
229
|
-
}
|
|
230
|
-
return true;
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Cleans up the supplementary error and information text of input inside the {@link #hexInputRow}
|
|
234
|
-
* bringing them back to the state when the form has been displayed for the first time.
|
|
235
|
-
*
|
|
236
|
-
* See {@link #isValid}.
|
|
237
|
-
*/
|
|
238
|
-
resetValidationStatus() {
|
|
239
|
-
this.hexInputRow.inputView.errorText = null;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
// Converts any color format to a unified hex format.
|
|
243
|
-
//
|
|
244
|
-
// @param inputColor
|
|
245
|
-
// @returns An unified hex string.
|
|
246
|
-
function convertColorToCommonHexFormat(inputColor) {
|
|
247
|
-
let ret = convertToHex(inputColor);
|
|
248
|
-
if (!ret) {
|
|
249
|
-
ret = '#000';
|
|
250
|
-
}
|
|
251
|
-
if (ret.length === 4) {
|
|
252
|
-
// Unfold shortcut format.
|
|
253
|
-
ret = '#' + [ret[1], ret[1], ret[2], ret[2], ret[3], ret[3]].join('');
|
|
254
|
-
}
|
|
255
|
-
return ret.toLowerCase();
|
|
256
|
-
}
|
|
257
|
-
// View abstraction over pointer in color picker.
|
|
258
|
-
export class SliderView extends View {
|
|
259
|
-
/**
|
|
260
|
-
* @param element HTML element of slider in color picker.
|
|
261
|
-
*/
|
|
262
|
-
constructor(element) {
|
|
263
|
-
super();
|
|
264
|
-
this.element = element;
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Focuses element.
|
|
268
|
-
*/
|
|
269
|
-
focus() {
|
|
270
|
-
this.element.focus();
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
// View abstraction over the `#` character before color input.
|
|
274
|
-
class HashView extends View {
|
|
275
|
-
constructor(locale) {
|
|
276
|
-
super(locale);
|
|
277
|
-
this.setTemplate({
|
|
278
|
-
tag: 'div',
|
|
279
|
-
attributes: {
|
|
280
|
-
class: [
|
|
281
|
-
'ck',
|
|
282
|
-
'ck-color-picker__hash-view'
|
|
283
|
-
]
|
|
284
|
-
},
|
|
285
|
-
children: '#'
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
// The class representing a row containing hex color input field.
|
|
290
|
-
// **Note**: For now this class is private. When more use cases appear (beyond `ckeditor5-table` and `ckeditor5-image`),
|
|
291
|
-
// it will become a component in `ckeditor5-ui`.
|
|
292
|
-
//
|
|
293
|
-
// @private
|
|
294
|
-
export class ColorPickerInputRowView extends View {
|
|
295
|
-
/**
|
|
296
|
-
* A collection of row items (buttons, dropdowns, etc.).
|
|
297
|
-
*/
|
|
298
|
-
children;
|
|
299
|
-
/**
|
|
300
|
-
* Hex input view element.
|
|
301
|
-
*/
|
|
302
|
-
inputView;
|
|
303
|
-
/**
|
|
304
|
-
* Creates an instance of the form row class.
|
|
305
|
-
*
|
|
306
|
-
* @param locale The locale instance.
|
|
307
|
-
* @param inputView Hex color input element.
|
|
308
|
-
*/
|
|
309
|
-
constructor(locale, inputView) {
|
|
310
|
-
super(locale);
|
|
311
|
-
this.inputView = inputView;
|
|
312
|
-
this.children = this.createCollection([
|
|
313
|
-
new HashView(),
|
|
314
|
-
this.inputView
|
|
315
|
-
]);
|
|
316
|
-
this.setTemplate({
|
|
317
|
-
tag: 'div',
|
|
318
|
-
attributes: {
|
|
319
|
-
class: [
|
|
320
|
-
'ck',
|
|
321
|
-
'ck-color-picker__row'
|
|
322
|
-
]
|
|
323
|
-
},
|
|
324
|
-
children: this.children
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Returns false if color input value is not in hex format.
|
|
329
|
-
*/
|
|
330
|
-
getParsedColor() {
|
|
331
|
-
return tryParseHexColor(this.inputView.fieldView.element.value);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Trim spaces from provided color and check if hex is valid.
|
|
336
|
-
*
|
|
337
|
-
* @param color Unsafe color string.
|
|
338
|
-
* @returns Null if provided color is not hex value.
|
|
339
|
-
* @export
|
|
340
|
-
* @internal
|
|
341
|
-
*/
|
|
342
|
-
export function tryParseHexColor(color) {
|
|
343
|
-
if (!color) {
|
|
344
|
-
return null;
|
|
345
|
-
}
|
|
346
|
-
const hashLessColor = color.trim().replace(/^#/, '');
|
|
347
|
-
// Incorrect length.
|
|
348
|
-
if (![3, 4, 6, 8].includes(hashLessColor.length)) {
|
|
349
|
-
return null;
|
|
350
|
-
}
|
|
351
|
-
// Incorrect characters.
|
|
352
|
-
if (!/^(([0-9a-fA-F]{2}){3,4}|([0-9a-fA-F]){3,4})$/.test(hashLessColor)) {
|
|
353
|
-
return null;
|
|
354
|
-
}
|
|
355
|
-
return `#${hashLessColor}`;
|
|
356
|
-
}
|
package/src/colorpicker/utils.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module ui/colorpicker/utils
|
|
7
|
-
*/
|
|
8
|
-
import { default as parse } from 'color-parse';
|
|
9
|
-
import convert from 'color-convert';
|
|
10
|
-
/**
|
|
11
|
-
* Parses and converts the color string to requested format. Handles variety of color spaces
|
|
12
|
-
* like `hsl`, `hex` or `rgb`.
|
|
13
|
-
*
|
|
14
|
-
* @param color
|
|
15
|
-
* @returns A color string.
|
|
16
|
-
* @internal
|
|
17
|
-
*/
|
|
18
|
-
export function convertColor(color, outputFormat) {
|
|
19
|
-
if (!color) {
|
|
20
|
-
return '';
|
|
21
|
-
}
|
|
22
|
-
const colorObject = parseColorString(color);
|
|
23
|
-
if (!colorObject) {
|
|
24
|
-
return '';
|
|
25
|
-
}
|
|
26
|
-
if (colorObject.space === outputFormat) {
|
|
27
|
-
return color;
|
|
28
|
-
}
|
|
29
|
-
if (!canConvertParsedColor(colorObject)) {
|
|
30
|
-
return '';
|
|
31
|
-
}
|
|
32
|
-
const fromColorSpace = convert[colorObject.space];
|
|
33
|
-
const toColorSpace = fromColorSpace[outputFormat];
|
|
34
|
-
if (!toColorSpace) {
|
|
35
|
-
return '';
|
|
36
|
-
}
|
|
37
|
-
const convertedColorChannels = toColorSpace(colorObject.space === 'hex' ? colorObject.hexValue : colorObject.values);
|
|
38
|
-
return formatColorOutput(convertedColorChannels, outputFormat);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Converts a color string to hex format.
|
|
42
|
-
*
|
|
43
|
-
* @param color
|
|
44
|
-
* @returns A color string.
|
|
45
|
-
* @internal
|
|
46
|
-
*/
|
|
47
|
-
export function convertToHex(color) {
|
|
48
|
-
if (!color) {
|
|
49
|
-
return '';
|
|
50
|
-
}
|
|
51
|
-
const colorObject = parseColorString(color);
|
|
52
|
-
if (!colorObject) {
|
|
53
|
-
return '#000';
|
|
54
|
-
}
|
|
55
|
-
if (colorObject.space === 'hex') {
|
|
56
|
-
return colorObject.hexValue;
|
|
57
|
-
}
|
|
58
|
-
return convertColor(color, 'hex');
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Registers the custom element in the
|
|
62
|
-
* [CustomElementsRegistry](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry).
|
|
63
|
-
* @internal
|
|
64
|
-
*/
|
|
65
|
-
export function registerCustomElement(elementName, constructor) {
|
|
66
|
-
if (customElements.get(elementName) === undefined) {
|
|
67
|
-
customElements.define(elementName, constructor);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Formats the passed color channels according to the requested format.
|
|
72
|
-
*
|
|
73
|
-
* @param values
|
|
74
|
-
* @param format
|
|
75
|
-
* @returns A color string.
|
|
76
|
-
*/
|
|
77
|
-
function formatColorOutput(values, format) {
|
|
78
|
-
switch (format) {
|
|
79
|
-
case 'hex': return `#${values}`;
|
|
80
|
-
case 'rgb': return `rgb(${values[0]}, ${values[1]}, ${values[2]})`;
|
|
81
|
-
case 'hsl': return `hsl(${values[0]}, ${values[1]}%, ${values[2]}%)`;
|
|
82
|
-
case 'hwb': return `hwb(${values[0]}, ${values[1]}, ${values[2]})`;
|
|
83
|
-
case 'lab': return `lab(${values[0]}% ${values[1]} ${values[2]})`;
|
|
84
|
-
case 'lch': return `lch(${values[0]}% ${values[1]} ${values[2]})`;
|
|
85
|
-
default: return '';
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
function parseColorString(colorString) {
|
|
89
|
-
// Parser library treats `hex` format as belonging to `rgb` space | which messes up further conversion.
|
|
90
|
-
// Let's parse such strings on our own.
|
|
91
|
-
if (colorString.startsWith('#')) {
|
|
92
|
-
const parsedHex = parse(colorString);
|
|
93
|
-
return {
|
|
94
|
-
space: 'hex',
|
|
95
|
-
values: parsedHex.values,
|
|
96
|
-
hexValue: colorString,
|
|
97
|
-
alpha: parsedHex.alpha
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
const parsed = parse(colorString);
|
|
101
|
-
if (!parsed.space) {
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
return parsed;
|
|
105
|
-
}
|
|
106
|
-
function canConvertParsedColor(parsedColor) {
|
|
107
|
-
return Object.keys(convert).includes(parsedColor.space);
|
|
108
|
-
}
|