wj-elements 0.2.0-alpha.8 → 0.3.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/dist/dark.css +15 -1
- package/dist/{form-associated-element-o0UjvdUp.js → form-associated-element-DEQ4y-jn.js} +1 -2
- package/dist/form-associated-element-DEQ4y-jn.js.map +1 -0
- package/dist/{icon-DY5AZ6xM.js → icon-DVyMc4Wv.js} +36 -2
- package/dist/{icon-DY5AZ6xM.js.map → icon-DVyMc4Wv.js.map} +1 -1
- package/dist/light.css +7 -2
- package/dist/localize.js +8 -5
- package/dist/localize.js.map +1 -1
- package/dist/packages/internals/form-associated-element.d.ts +0 -1
- package/dist/packages/utils/utils.d.ts +16 -0
- package/dist/packages/wje-accordion-item/accordion-item.element.d.ts +3 -0
- package/dist/packages/wje-avatar/avatar.element.d.ts +5 -0
- package/dist/packages/wje-breadcrumb/breadcrumb.element.d.ts +1 -0
- package/dist/packages/wje-button/button.element.d.ts +5 -1
- package/dist/packages/wje-button-group/button-group.element.d.ts +4 -0
- package/dist/packages/wje-card/card.element.d.ts +15 -6
- package/dist/packages/wje-carousel/carousel.element.d.ts +4 -0
- package/dist/packages/wje-checkbox/checkbox.element.d.ts +14 -0
- package/dist/packages/wje-chip/chip.element.d.ts +6 -0
- package/dist/packages/wje-color-picker/color-picker.element.d.ts +43 -1
- package/dist/packages/wje-copy-button/copy-button.element.d.ts +4 -0
- package/dist/packages/wje-dialog/dialog.element.d.ts +2 -0
- package/dist/packages/wje-dropdown/dropdown.element.d.ts +7 -0
- package/dist/packages/wje-element/element.d.ts +55 -24
- package/dist/packages/wje-file-upload/file-upload.element.d.ts +17 -6
- package/dist/packages/wje-file-upload/service/service.d.ts +0 -23
- package/dist/packages/wje-file-upload-item/file-upload-item.element.d.ts +6 -0
- package/dist/packages/wje-format-digital/format-digital.element.d.ts +2 -0
- package/dist/packages/wje-icon/icon.element.d.ts +11 -0
- package/dist/packages/wje-icon-picker/icon-picker.element.d.ts +4 -0
- package/dist/packages/wje-img/img.element.d.ts +1 -0
- package/dist/packages/wje-infinite-scroll/infinite-scroll.element.d.ts +4 -0
- package/dist/packages/wje-input/input.element.d.ts +9 -1
- package/dist/packages/wje-item/item.element.d.ts +8 -0
- package/dist/packages/wje-kanban/kanban.element.d.ts +4 -0
- package/dist/packages/wje-level-indicator/level-indicator.element.d.ts +17 -0
- package/dist/packages/wje-list/list.element.d.ts +4 -0
- package/dist/packages/wje-menu-item/menu-item.element.d.ts +4 -0
- package/dist/packages/wje-option/option.element.d.ts +4 -0
- package/dist/packages/wje-options/options.element.d.ts +4 -0
- package/dist/packages/wje-orgchart/orgchart.element.d.ts +4 -0
- package/dist/packages/wje-progress-bar/progress-bar.element.d.ts +11 -0
- package/dist/packages/wje-qr-code/qr-code.element.d.ts +63 -0
- package/dist/packages/wje-radio/radio.element.d.ts +5 -0
- package/dist/packages/wje-radio-group/radio-group.element.d.ts +16 -1
- package/dist/packages/wje-rate/rate.element.d.ts +4 -0
- package/dist/packages/wje-relative-time/relative-time.element.d.ts +2 -0
- package/dist/packages/wje-reorder/reorder.element.d.ts +4 -0
- package/dist/packages/wje-reorder-handle/reorder-handle.element.d.ts +4 -0
- package/dist/packages/wje-select/select.element.d.ts +7 -0
- package/dist/packages/wje-slider/slider.element.d.ts +5 -0
- package/dist/packages/wje-sliding-container/sliding-container.element.d.ts +4 -0
- package/dist/packages/wje-split-view/split-view.element.d.ts +1 -0
- package/dist/packages/wje-stepper/stepper.element.d.ts +1 -0
- package/dist/packages/wje-tab/tab.element.d.ts +10 -0
- package/dist/packages/wje-tab-group/tab-group.element.d.ts +11 -0
- package/dist/packages/wje-textarea/textarea.element.d.ts +20 -1
- package/dist/packages/wje-thumbnail/thumbnail.element.d.ts +4 -0
- package/dist/packages/wje-timeline/timeline.element.d.ts +4 -0
- package/dist/packages/wje-toggle/toggle.element.d.ts +4 -0
- package/dist/packages/wje-toolbar/toolbar.element.d.ts +4 -0
- package/dist/packages/wje-tooltip/tooltip.element.d.ts +3 -0
- package/dist/packages/wje-tree/tree.element.d.ts +4 -0
- package/dist/packages/wje-tree-item/tree-item.element.d.ts +5 -0
- package/dist/{popup.element-DeajFyOQ.js → popup.element-Cl6QeG8M.js} +2 -2
- package/dist/{popup.element-DeajFyOQ.js.map → popup.element-Cl6QeG8M.js.map} +1 -1
- package/dist/skeleton.css +197 -0
- package/dist/utils.js +18 -1
- package/dist/utils.js.map +1 -1
- package/dist/wje-accordion-item.js +26 -4
- package/dist/wje-accordion-item.js.map +1 -1
- package/dist/wje-accordion.js +1 -0
- package/dist/wje-accordion.js.map +1 -1
- package/dist/wje-animation.js +1 -0
- package/dist/wje-animation.js.map +1 -1
- package/dist/wje-avatar.js +18 -0
- package/dist/wje-avatar.js.map +1 -1
- package/dist/wje-badge.js +1 -0
- package/dist/wje-badge.js.map +1 -1
- package/dist/wje-breadcrumb.js +13 -1
- package/dist/wje-breadcrumb.js.map +1 -1
- package/dist/wje-breadcrumbs.js +1 -0
- package/dist/wje-breadcrumbs.js.map +1 -1
- package/dist/wje-button-group.js +10 -0
- package/dist/wje-button-group.js.map +1 -1
- package/dist/wje-button.js +29 -5
- package/dist/wje-button.js.map +1 -1
- package/dist/wje-card.js +37 -0
- package/dist/wje-card.js.map +1 -1
- package/dist/wje-carousel.js +38 -4
- package/dist/wje-carousel.js.map +1 -1
- package/dist/wje-checkbox.js +48 -3
- package/dist/wje-checkbox.js.map +1 -1
- package/dist/wje-chip.js +22 -0
- package/dist/wje-chip.js.map +1 -1
- package/dist/wje-color-picker.js +143 -29
- package/dist/wje-color-picker.js.map +1 -1
- package/dist/wje-copy-button.js +21 -0
- package/dist/wje-copy-button.js.map +1 -1
- package/dist/wje-dialog.js +35 -2
- package/dist/wje-dialog.js.map +1 -1
- package/dist/wje-dropdown.js +27 -3
- package/dist/wje-dropdown.js.map +1 -1
- package/dist/wje-element.js +87 -242
- package/dist/wje-element.js.map +1 -1
- package/dist/wje-file-upload-item.js +24 -2
- package/dist/wje-file-upload-item.js.map +1 -1
- package/dist/wje-file-upload.js +100 -77
- package/dist/wje-file-upload.js.map +1 -1
- package/dist/wje-format-digital.js +9 -0
- package/dist/wje-format-digital.js.map +1 -1
- package/dist/wje-icon-picker.js +15 -0
- package/dist/wje-icon-picker.js.map +1 -1
- package/dist/wje-icon.js +1 -1
- package/dist/wje-img-comparer.js +5 -1
- package/dist/wje-img-comparer.js.map +1 -1
- package/dist/wje-img.js +16 -1
- package/dist/wje-img.js.map +1 -1
- package/dist/wje-infinite-scroll.js +10 -0
- package/dist/wje-infinite-scroll.js.map +1 -1
- package/dist/wje-input-file.js +2 -0
- package/dist/wje-input-file.js.map +1 -1
- package/dist/wje-input.js +59 -4
- package/dist/wje-input.js.map +1 -1
- package/dist/wje-item.js +14 -0
- package/dist/wje-item.js.map +1 -1
- package/dist/wje-kanban.js +14 -0
- package/dist/wje-kanban.js.map +1 -1
- package/dist/wje-level-indicator.js +36 -0
- package/dist/wje-level-indicator.js.map +1 -1
- package/dist/wje-list.js +10 -0
- package/dist/wje-list.js.map +1 -1
- package/dist/wje-master.js +11 -2
- package/dist/wje-master.js.map +1 -1
- package/dist/wje-menu-button.js +1 -0
- package/dist/wje-menu-button.js.map +1 -1
- package/dist/wje-menu-item.js +24 -0
- package/dist/wje-menu-item.js.map +1 -1
- package/dist/wje-menu.js +4 -1
- package/dist/wje-menu.js.map +1 -1
- package/dist/wje-option.js +14 -1
- package/dist/wje-option.js.map +1 -1
- package/dist/wje-options.js +13 -0
- package/dist/wje-options.js.map +1 -1
- package/dist/wje-orgchart.js +9 -0
- package/dist/wje-orgchart.js.map +1 -1
- package/dist/wje-pagination.js +18 -9
- package/dist/wje-pagination.js.map +1 -1
- package/dist/wje-popup.js +1 -1
- package/dist/wje-progress-bar.js +26 -0
- package/dist/wje-progress-bar.js.map +1 -1
- package/dist/wje-qr-code.js +159 -17
- package/dist/wje-qr-code.js.map +1 -1
- package/dist/wje-radio-group.js +49 -2
- package/dist/wje-radio-group.js.map +1 -1
- package/dist/wje-radio.js +27 -1
- package/dist/wje-radio.js.map +1 -1
- package/dist/wje-rate.js +23 -1
- package/dist/wje-rate.js.map +1 -1
- package/dist/wje-relative-time.js +14 -1
- package/dist/wje-relative-time.js.map +1 -1
- package/dist/wje-reorder-handle.js +21 -0
- package/dist/wje-reorder-handle.js.map +1 -1
- package/dist/wje-reorder.js +10 -0
- package/dist/wje-reorder.js.map +1 -1
- package/dist/wje-select.js +35 -5
- package/dist/wje-select.js.map +1 -1
- package/dist/wje-slider.js +51 -1
- package/dist/wje-slider.js.map +1 -1
- package/dist/wje-sliding-container.js +18 -0
- package/dist/wje-sliding-container.js.map +1 -1
- package/dist/wje-split-view.js +9 -0
- package/dist/wje-split-view.js.map +1 -1
- package/dist/wje-status.js +1 -0
- package/dist/wje-status.js.map +1 -1
- package/dist/wje-stepper.js +24 -1
- package/dist/wje-stepper.js.map +1 -1
- package/dist/wje-tab-group.js +59 -2
- package/dist/wje-tab-group.js.map +1 -1
- package/dist/wje-tab.js +30 -0
- package/dist/wje-tab.js.map +1 -1
- package/dist/wje-textarea.js +96 -14
- package/dist/wje-textarea.js.map +1 -1
- package/dist/wje-thumbnail.js +19 -0
- package/dist/wje-thumbnail.js.map +1 -1
- package/dist/wje-toast.js +4 -0
- package/dist/wje-toast.js.map +1 -1
- package/dist/wje-toggle.js +17 -1
- package/dist/wje-toggle.js.map +1 -1
- package/dist/wje-toolbar.js +14 -0
- package/dist/wje-toolbar.js.map +1 -1
- package/dist/wje-tooltip.js +31 -7
- package/dist/wje-tooltip.js.map +1 -1
- package/dist/wje-tree-item.js +41 -5
- package/dist/wje-tree-item.js.map +1 -1
- package/dist/wje-tree.js +12 -1
- package/dist/wje-tree.js.map +1 -1
- package/package.json +21 -2
- package/dist/form-associated-element-o0UjvdUp.js.map +0 -1
- package/dist/packages/wje-accordion/accordion.test.d.ts +0 -0
- package/dist/packages/wje-animation/animation.test.d.ts +0 -1
- package/dist/packages/wje-avatar/avatar.test.d.ts +0 -1
- package/dist/packages/wje-badge/badge.test.d.ts +0 -1
- package/dist/packages/wje-breadcrumbs/breadcrumbs.test.d.ts +0 -1
- package/dist/packages/wje-button/button.test.d.ts +0 -1
- package/dist/packages/wje-chip/chip.test.d.ts +0 -1
- package/dist/packages/wje-color-picker/color-picker.test.d.ts +0 -1
- package/dist/packages/wje-file-upload/file-upload.test.d.ts +0 -1
- package/dist/packages/wje-format-digital/format-digital.test.d.ts +0 -1
- package/dist/packages/wje-pagination/pagination.test.d.ts +0 -1
- package/dist/packages/wje-relative-time/relative-time.test.d.ts +0 -1
- package/dist/packages/wje-select/select.test.d.ts +0 -1
- package/dist/packages/wje-tab-group/tab-group.test.d.ts +0 -1
- package/dist/packages/wje-toast/toast.test.d.ts +0 -1
- package/dist/packages/wje-toggle/toggle.test.d.ts +0 -1
- package/dist/packages/wje-tree/tree.test.d.ts +0 -1
- package/dist/packages/wje-tree-item/tree-item.test.d.ts +0 -1
package/dist/wje-color-picker.js
CHANGED
|
@@ -992,12 +992,15 @@ class ColorPicker extends WJElement {
|
|
|
992
992
|
* @param {Event} e The event triggering the marker movement, typically a mouse or touch event.
|
|
993
993
|
*/
|
|
994
994
|
__publicField(this, "moveMarker", (e) => {
|
|
995
|
+
var _a;
|
|
995
996
|
this.colorAreaDimension = this.dimension();
|
|
996
997
|
const pointer = this.getPointerPosition(e);
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
this.
|
|
1000
|
-
this.
|
|
998
|
+
const x = pointer.x - this.colorAreaDimension.x;
|
|
999
|
+
const y = pointer.y - this.colorAreaDimension.y;
|
|
1000
|
+
const markerPosition = this.clampMarkerPosition(x, y);
|
|
1001
|
+
const alpha = Number(((_a = this.alphaSlider) == null ? void 0 : _a.value) || 100);
|
|
1002
|
+
this.setColor(this.setColorAtPosition(markerPosition.x, markerPosition.y, alpha), "marker");
|
|
1003
|
+
this.setMarkerPosition(markerPosition.x, markerPosition.y);
|
|
1001
1004
|
});
|
|
1002
1005
|
/**
|
|
1003
1006
|
* Sets the marker position by color.
|
|
@@ -1005,16 +1008,21 @@ class ColorPicker extends WJElement {
|
|
|
1005
1008
|
* @returns {{x: number, y: number}}
|
|
1006
1009
|
*/
|
|
1007
1010
|
__publicField(this, "setMarkerPositionByColor", (color = "red") => {
|
|
1011
|
+
var _a, _b;
|
|
1008
1012
|
let hsva = tinycolor(color).toHsv();
|
|
1013
|
+
const width = ((_a = this.colorAreaDimension) == null ? void 0 : _a.width) || 0;
|
|
1014
|
+
const height = ((_b = this.colorAreaDimension) == null ? void 0 : _b.height) || 0;
|
|
1015
|
+
const safeS = Number.isFinite(hsva.s) ? hsva.s : 0;
|
|
1016
|
+
const safeV = Number.isFinite(hsva.v) ? hsva.v : 0;
|
|
1009
1017
|
return {
|
|
1010
|
-
x:
|
|
1011
|
-
y:
|
|
1018
|
+
x: width * safeS,
|
|
1019
|
+
y: height - height * safeV
|
|
1012
1020
|
};
|
|
1013
1021
|
});
|
|
1014
1022
|
/**
|
|
1015
1023
|
* Updates the color picker's current color and its associated UI elements.
|
|
1016
1024
|
* @param {tinycolor.Instance|null} [color] The color value to set. If null, the current value from the input field is used.
|
|
1017
|
-
* @param {string} [type] The type of action determining which UI element to update. Possible values: "marker", "hue", "alpha", "swatch".
|
|
1025
|
+
* @param {string} [type] The type of action determining which UI element to update. Possible values: "marker", "hue", "alpha", "swatch", "input".
|
|
1018
1026
|
*/
|
|
1019
1027
|
__publicField(this, "setColor", (color = null, type = "") => {
|
|
1020
1028
|
let currentColor = color;
|
|
@@ -1023,7 +1031,6 @@ class ColorPicker extends WJElement {
|
|
|
1023
1031
|
this.colorArea.style.setProperty("--wje-color-picker-area", currentColor.toHexString());
|
|
1024
1032
|
}
|
|
1025
1033
|
if (type === "marker") {
|
|
1026
|
-
this.alphaSlider.value = 100;
|
|
1027
1034
|
this.alphaSlider.style.setProperty("--wje-color-picker-value", currentColor.toHexString());
|
|
1028
1035
|
this.colorPreview.style.setProperty("--wje-color-picker-value", currentColor.toHex8String());
|
|
1029
1036
|
this.picker.style.setProperty("--wje-color-picker-value", currentColor.toHexString());
|
|
@@ -1035,12 +1042,13 @@ class ColorPicker extends WJElement {
|
|
|
1035
1042
|
this.markerPosition.y,
|
|
1036
1043
|
this.alphaSlider.value
|
|
1037
1044
|
);
|
|
1038
|
-
|
|
1045
|
+
const hueColor = this.getHueAreaColor(this.getHSVA(this.hueSlider.value, 100));
|
|
1039
1046
|
this.colorPreview.style.setProperty("--wje-color-picker-value", markerColorByPosition.toHex8String());
|
|
1040
1047
|
this.marker.style.setProperty("--wje-color-picker-value", markerColorByPosition.toHexString());
|
|
1041
|
-
this.alphaSlider.style.setProperty("--wje-color-picker-value",
|
|
1042
|
-
this.colorArea.style.setProperty("--wje-color-picker-area",
|
|
1048
|
+
this.alphaSlider.style.setProperty("--wje-color-picker-value", markerColorByPosition.toHexString());
|
|
1049
|
+
this.colorArea.style.setProperty("--wje-color-picker-area", hueColor);
|
|
1043
1050
|
this.input.value = markerColorByPosition.toHex8String();
|
|
1051
|
+
currentColor = markerColorByPosition;
|
|
1044
1052
|
}
|
|
1045
1053
|
if (type === "alpha") {
|
|
1046
1054
|
currentColor = tinycolor(this.input.value);
|
|
@@ -1049,16 +1057,21 @@ class ColorPicker extends WJElement {
|
|
|
1049
1057
|
currentColor = tinycolor(hsv);
|
|
1050
1058
|
this.colorPreview.style.setProperty("--wje-color-picker-value", currentColor.toHex8String());
|
|
1051
1059
|
}
|
|
1052
|
-
if (type === "swatch" || type === "init") {
|
|
1060
|
+
if (type === "swatch" || type === "init" || type === "input") {
|
|
1053
1061
|
this.colorPreview.style.setProperty("--wje-color-picker-value", currentColor.toHex8String());
|
|
1054
1062
|
this.marker.style.setProperty("--wje-color-picker-value", currentColor.toHexString());
|
|
1055
1063
|
this.alphaSlider.style.setProperty("--wje-color-picker-value", currentColor.toHexString());
|
|
1056
|
-
this.colorArea.style.setProperty("--wje-color-picker-area", currentColor.toHex8String());
|
|
1064
|
+
this.colorArea.style.setProperty("--wje-color-picker-area", this.getHueAreaColor(currentColor.toHex8String()));
|
|
1057
1065
|
this.markerPosition = this.setMarkerPositionByColor(currentColor.toHex8String());
|
|
1058
1066
|
this.setMarkerPosition(this.markerPosition.x, this.markerPosition.y);
|
|
1059
1067
|
}
|
|
1068
|
+
if (!(currentColor == null ? void 0 : currentColor.isValid())) return;
|
|
1060
1069
|
if (!this.noColorArea || !this.noControls || !this.noSwatches) {
|
|
1061
|
-
this.
|
|
1070
|
+
if (type === "input" && this.inputEditable && typeof this._manualInputValue === "string") {
|
|
1071
|
+
this.input.value = this._manualInputValue;
|
|
1072
|
+
} else {
|
|
1073
|
+
this.input.value = currentColor.toHex8String();
|
|
1074
|
+
}
|
|
1062
1075
|
}
|
|
1063
1076
|
this.anchor.style.setProperty("--wje-color-picker-value", currentColor.toHexString());
|
|
1064
1077
|
this.value = {
|
|
@@ -1120,6 +1133,7 @@ class ColorPicker extends WJElement {
|
|
|
1120
1133
|
"#00b4d880",
|
|
1121
1134
|
"rgba(0,119,182,0.8)"
|
|
1122
1135
|
];
|
|
1136
|
+
this._manualInputValue = null;
|
|
1123
1137
|
}
|
|
1124
1138
|
/**
|
|
1125
1139
|
* Sets the color attribute of the element.
|
|
@@ -1154,16 +1168,30 @@ class ColorPicker extends WJElement {
|
|
|
1154
1168
|
* @param {string} value The new color swatches.
|
|
1155
1169
|
*/
|
|
1156
1170
|
set swatches(value) {
|
|
1157
|
-
|
|
1171
|
+
if (Array.isArray(value)) {
|
|
1172
|
+
this.setAttribute("swatches", value.join(","));
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
1175
|
+
this.setAttribute("swatches", this.parseSwatches(value).join(","));
|
|
1158
1176
|
}
|
|
1159
1177
|
/**
|
|
1160
1178
|
* Getter for the color swatches.
|
|
1161
1179
|
* @returns {Array} The current color swatches.
|
|
1162
1180
|
*/
|
|
1163
1181
|
get swatches() {
|
|
1164
|
-
this._swatches = this.getAttribute("swatches") ? this.getAttribute("swatches")
|
|
1182
|
+
this._swatches = this.getAttribute("swatches") ? this.parseSwatches(this.getAttribute("swatches")) : this._swatches;
|
|
1165
1183
|
return this._swatches;
|
|
1166
1184
|
}
|
|
1185
|
+
/**
|
|
1186
|
+
* Normalizes swatch colors from a string to an array.
|
|
1187
|
+
* Supports comma and semicolon separators.
|
|
1188
|
+
* @param {string} value
|
|
1189
|
+
* @returns {string[]}
|
|
1190
|
+
*/
|
|
1191
|
+
parseSwatches(value = "") {
|
|
1192
|
+
if (typeof value !== "string") return [];
|
|
1193
|
+
return value.split(/[;,]/).map((item) => item.trim()).filter(Boolean);
|
|
1194
|
+
}
|
|
1167
1195
|
/**
|
|
1168
1196
|
* Sets or removes the 'no-color-area' attribute based on the provided value.
|
|
1169
1197
|
* @param {boolean} value A boolean value indicating whether to set or remove the 'no-color-area' attribute. If true, the attribute is added; if false, the attribute is removed.
|
|
@@ -1220,6 +1248,24 @@ class ColorPicker extends WJElement {
|
|
|
1220
1248
|
get noSwatches() {
|
|
1221
1249
|
return this.hasAttribute("no-swatches");
|
|
1222
1250
|
}
|
|
1251
|
+
/**
|
|
1252
|
+
* Enables/disables manual typing in the input.
|
|
1253
|
+
* @param {boolean} value
|
|
1254
|
+
*/
|
|
1255
|
+
set inputEditable(value) {
|
|
1256
|
+
if (value) {
|
|
1257
|
+
this.setAttribute("input-editable", "");
|
|
1258
|
+
} else {
|
|
1259
|
+
this.removeAttribute("input-editable");
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
/**
|
|
1263
|
+
* Returns true when manual input typing is enabled.
|
|
1264
|
+
* @returns {boolean}
|
|
1265
|
+
*/
|
|
1266
|
+
get inputEditable() {
|
|
1267
|
+
return this.hasAttribute("input-editable");
|
|
1268
|
+
}
|
|
1223
1269
|
/**
|
|
1224
1270
|
* Getter for the CSS stylesheet.
|
|
1225
1271
|
* @returns {object} The styles object.
|
|
@@ -1294,11 +1340,30 @@ class ColorPicker extends WJElement {
|
|
|
1294
1340
|
colorPreview.classList.add("color-preview");
|
|
1295
1341
|
let input = document.createElement("wje-input");
|
|
1296
1342
|
input.setAttribute("variant", "standard");
|
|
1297
|
-
|
|
1343
|
+
input.setAttribute("maxlength", "9");
|
|
1344
|
+
if ((!this.noColorArea || !this.noControls || !this.noSwatches) && !this.inputEditable)
|
|
1298
1345
|
input.setAttribute("readonly", "");
|
|
1299
1346
|
input.classList.add("input");
|
|
1300
|
-
input.addEventListener("wje-input:input", (
|
|
1301
|
-
|
|
1347
|
+
input.addEventListener("wje-input:input", () => {
|
|
1348
|
+
let rawValue = (input.value || "").trim();
|
|
1349
|
+
const hasHashPrefix = rawValue.startsWith("#");
|
|
1350
|
+
const maxLength = hasHashPrefix ? 9 : 8;
|
|
1351
|
+
if (rawValue.length > maxLength) {
|
|
1352
|
+
rawValue = rawValue.slice(0, maxLength);
|
|
1353
|
+
input.value = rawValue;
|
|
1354
|
+
}
|
|
1355
|
+
const hexCandidate = hasHashPrefix ? rawValue.slice(1) : rawValue;
|
|
1356
|
+
const isHex = /^[0-9a-fA-F]+$/.test(hexCandidate);
|
|
1357
|
+
if (isHex) {
|
|
1358
|
+
if (hexCandidate.length < 6) return;
|
|
1359
|
+
if (![6, 8].includes(hexCandidate.length)) return;
|
|
1360
|
+
}
|
|
1361
|
+
const parsedColor = tinycolor(isHex ? `#${hexCandidate}` : rawValue);
|
|
1362
|
+
if (!parsedColor.isValid()) return;
|
|
1363
|
+
this._manualInputValue = rawValue;
|
|
1364
|
+
this.setSliders(parsedColor.toHex8String());
|
|
1365
|
+
this.setColor(parsedColor, "input");
|
|
1366
|
+
this._manualInputValue = null;
|
|
1302
1367
|
});
|
|
1303
1368
|
colorArea.append(marker);
|
|
1304
1369
|
alphaWrapper.append(alphaSlider);
|
|
@@ -1352,10 +1417,12 @@ class ColorPicker extends WJElement {
|
|
|
1352
1417
|
let swatches = document.createElement("div");
|
|
1353
1418
|
swatches.classList.add("swatches");
|
|
1354
1419
|
this.swatches.forEach((swatch) => {
|
|
1420
|
+
if (!tinycolor(swatch).isValid()) return;
|
|
1355
1421
|
let button = document.createElement("button");
|
|
1422
|
+
button.setAttribute("type", "button");
|
|
1356
1423
|
button.classList.add("swatch");
|
|
1357
1424
|
button.style.setProperty("--wje-color-picker-swatch", swatch);
|
|
1358
|
-
button.addEventListener("click", (
|
|
1425
|
+
button.addEventListener("click", () => {
|
|
1359
1426
|
this.setSliders(swatch);
|
|
1360
1427
|
this.setColor(tinycolor(swatch), "swatch");
|
|
1361
1428
|
});
|
|
@@ -1416,14 +1483,30 @@ class ColorPicker extends WJElement {
|
|
|
1416
1483
|
* @param y
|
|
1417
1484
|
*/
|
|
1418
1485
|
setMarkerPosition(x, y) {
|
|
1419
|
-
|
|
1420
|
-
y = y < 0 ? 0 : y > this.colorAreaDimension.height ? this.colorAreaDimension.height : y;
|
|
1486
|
+
const markerPosition = this.clampMarkerPosition(x, y);
|
|
1421
1487
|
this.markerPosition = {
|
|
1422
|
-
x,
|
|
1423
|
-
y
|
|
1488
|
+
x: markerPosition.x,
|
|
1489
|
+
y: markerPosition.y
|
|
1490
|
+
};
|
|
1491
|
+
this.marker.style.left = `${markerPosition.x}px`;
|
|
1492
|
+
this.marker.style.top = `${markerPosition.y}px`;
|
|
1493
|
+
}
|
|
1494
|
+
/**
|
|
1495
|
+
* Clamps marker coordinates to the color area boundaries.
|
|
1496
|
+
* @param {number} x
|
|
1497
|
+
* @param {number} y
|
|
1498
|
+
* @returns {{x: number, y: number}}
|
|
1499
|
+
*/
|
|
1500
|
+
clampMarkerPosition(x, y) {
|
|
1501
|
+
var _a, _b;
|
|
1502
|
+
const width = ((_a = this.colorAreaDimension) == null ? void 0 : _a.width) || 0;
|
|
1503
|
+
const height = ((_b = this.colorAreaDimension) == null ? void 0 : _b.height) || 0;
|
|
1504
|
+
const safeX = Number.isFinite(x) ? x : 0;
|
|
1505
|
+
const safeY = Number.isFinite(y) ? y : 0;
|
|
1506
|
+
return {
|
|
1507
|
+
x: Math.min(Math.max(safeX, 0), width),
|
|
1508
|
+
y: Math.min(Math.max(safeY, 0), height)
|
|
1424
1509
|
};
|
|
1425
|
-
this.marker.style.left = `${x}px`;
|
|
1426
|
-
this.marker.style.top = `${y}px`;
|
|
1427
1510
|
}
|
|
1428
1511
|
/**
|
|
1429
1512
|
* Sets the color at the given position.
|
|
@@ -1433,14 +1516,45 @@ class ColorPicker extends WJElement {
|
|
|
1433
1516
|
* @returns {*|tinycolor}
|
|
1434
1517
|
*/
|
|
1435
1518
|
setColorAtPosition(x, y, alpha = 100) {
|
|
1519
|
+
var _a, _b, _c;
|
|
1520
|
+
const markerPosition = this.clampMarkerPosition(x, y);
|
|
1521
|
+
const width = ((_a = this.colorAreaDimension) == null ? void 0 : _a.width) || 0;
|
|
1522
|
+
const height = ((_b = this.colorAreaDimension) == null ? void 0 : _b.height) || 0;
|
|
1523
|
+
const safeAlpha = Number.isFinite(Number(alpha)) ? Number(alpha) : 100;
|
|
1524
|
+
if (width <= 0 || height <= 0) {
|
|
1525
|
+
const fallbackHsv = tinycolor(((_c = this.input) == null ? void 0 : _c.value) || this.color).toHsv();
|
|
1526
|
+
return tinycolor({
|
|
1527
|
+
h: this.hueSlider.value * 1,
|
|
1528
|
+
s: fallbackHsv.s,
|
|
1529
|
+
v: fallbackHsv.v,
|
|
1530
|
+
a: Math.max(0, Math.min(100, safeAlpha)) / 100
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1436
1533
|
const hsva = {
|
|
1437
1534
|
h: this.hueSlider.value * 1,
|
|
1438
|
-
s: x /
|
|
1439
|
-
v: 100 - y /
|
|
1440
|
-
a:
|
|
1535
|
+
s: markerPosition.x / width * 100,
|
|
1536
|
+
v: 100 - markerPosition.y / height * 100,
|
|
1537
|
+
a: Math.max(0, Math.min(100, safeAlpha)) / 100
|
|
1441
1538
|
};
|
|
1442
1539
|
return tinycolor(hsva);
|
|
1443
1540
|
}
|
|
1541
|
+
/**
|
|
1542
|
+
* Returns fully saturated and bright color for the current hue.
|
|
1543
|
+
* Used as base color for the SV area so neutral grays do not black out the palette.
|
|
1544
|
+
* @param {string} color
|
|
1545
|
+
* @returns {string}
|
|
1546
|
+
*/
|
|
1547
|
+
getHueAreaColor(color = "#ff0000") {
|
|
1548
|
+
var _a;
|
|
1549
|
+
const hsv = tinycolor(color).toHsv();
|
|
1550
|
+
const hue = Number.isFinite(hsv.h) ? hsv.h : Number(((_a = this.hueSlider) == null ? void 0 : _a.value) || 0);
|
|
1551
|
+
return tinycolor({
|
|
1552
|
+
h: hue,
|
|
1553
|
+
s: 100,
|
|
1554
|
+
v: 100,
|
|
1555
|
+
a: 1
|
|
1556
|
+
}).toHexString();
|
|
1557
|
+
}
|
|
1444
1558
|
}
|
|
1445
1559
|
_init = new WeakMap();
|
|
1446
1560
|
WJElement.define("wje-color-picker", ColorPicker);
|