@ew-color-picker/box 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -19,11 +19,11 @@ ewColorPicker.use(Box)
|
|
|
19
19
|
const picker = new ewColorPicker({ el: '#picker' })
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
通常更推荐直接使用聚合包 `@ew-color-picker/
|
|
22
|
+
通常更推荐直接使用聚合包 `@ew-color-picker/ew-color-picker`,内置插件已全部注册。
|
|
23
23
|
|
|
24
24
|
## 相关链接
|
|
25
25
|
|
|
26
|
-
- 插件文档:https://eveningwater.github.io/ew-color-picker/plugins/box
|
|
26
|
+
- 插件文档:https://eveningwater.github.io/ew-color-picker/zh/plugins/box
|
|
27
27
|
- 源码仓库:https://github.com/eveningwater/ew-color-picker
|
|
28
28
|
|
|
29
29
|
## License
|
package/dist/box.esm.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* (c) 2024-2026 eveningwater(854806732@qq.com)
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
import { arrowIcon, closeIcon, colorToRgba, parseRgbaString, isShallowObject, isNumber, extend, createByTemplate, removeElement, warn, $, create, addClass, setStyle, insertNode, removeStyle, removeClass, on, off } from '@ew-color-picker/utils';
|
|
6
|
+
import { arrowIcon, closeIcon, colorToRgba, parseRgbaString, isShallowObject, isNumber, DEFAULT_PREFIX, extend, createByTemplate, removeElement, warn, $, create, addClass, setStyle, insertNode, removeStyle, removeClass, on, off, getPrefix } from '@ew-color-picker/utils';
|
|
7
7
|
|
|
8
8
|
/******************************************************************************
|
|
9
9
|
Copyright (c) Microsoft Corporation.
|
|
@@ -55,12 +55,12 @@ var ICON_SIZE_MAP = {
|
|
|
55
55
|
'large': 20 // 40px * 0.5
|
|
56
56
|
};
|
|
57
57
|
var getBoxChildren = function (hasColor, options) {
|
|
58
|
-
var _a = options.boxNoColorIcon, boxNoColorIcon = _a === void 0 ? "" : _a, _b = options.boxHasColorIcon, boxHasColorIcon = _b === void 0 ? "" : _b, size = options.size;
|
|
58
|
+
var _a = options.boxNoColorIcon, boxNoColorIcon = _a === void 0 ? "" : _a, _b = options.boxHasColorIcon, boxHasColorIcon = _b === void 0 ? "" : _b, size = options.size, _c = options.prefix, prefix = _c === void 0 ? DEFAULT_PREFIX : _c;
|
|
59
59
|
// 计算图标大小
|
|
60
60
|
var iconSize = calculateIconSize(size);
|
|
61
61
|
return hasColor
|
|
62
|
-
? boxHasColorIcon || arrowIcon("
|
|
63
|
-
: boxNoColorIcon || closeIcon("
|
|
62
|
+
? boxHasColorIcon || arrowIcon("".concat(prefix, "color-picker-box-arrow-icon"), iconSize, prefix)
|
|
63
|
+
: boxNoColorIcon || closeIcon("".concat(prefix, "color-picker-box-close-icon"), iconSize, prefix);
|
|
64
64
|
};
|
|
65
65
|
// 根据背景色亮度选择对比度更高的图标颜色
|
|
66
66
|
var getBoxIconColor = function (color) {
|
|
@@ -169,6 +169,13 @@ var ewColorPickerBoxPlugin = /** @class */ (function () {
|
|
|
169
169
|
}
|
|
170
170
|
this.run();
|
|
171
171
|
}
|
|
172
|
+
Object.defineProperty(ewColorPickerBoxPlugin.prototype, "prefix", {
|
|
173
|
+
get: function () {
|
|
174
|
+
return getPrefix(this.ewColorPicker);
|
|
175
|
+
},
|
|
176
|
+
enumerable: false,
|
|
177
|
+
configurable: true
|
|
178
|
+
});
|
|
172
179
|
Object.defineProperty(ewColorPickerBoxPlugin.prototype, "hasBox", {
|
|
173
180
|
// 获取盒子状态
|
|
174
181
|
get: function () {
|
|
@@ -250,10 +257,10 @@ var ewColorPickerBoxPlugin = /** @class */ (function () {
|
|
|
250
257
|
return;
|
|
251
258
|
}
|
|
252
259
|
// 查找或创建盒子容器
|
|
253
|
-
this.box = $(
|
|
260
|
+
this.box = $(".".concat(this.prefix, "color-picker-box"), rootElement);
|
|
254
261
|
if (!this.box) {
|
|
255
262
|
this.box = create("div");
|
|
256
|
-
addClass(this.box, "
|
|
263
|
+
addClass(this.box, "".concat(this.prefix, "color-picker-box"));
|
|
257
264
|
if (className)
|
|
258
265
|
addClass(this.box, className);
|
|
259
266
|
if (style)
|
package/dist/box.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
((o,t)=>{"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@ew-color-picker/utils")):"function"==typeof define&&define.amd?define(["@ew-color-picker/utils"],t):(o="undefined"!=typeof globalThis?globalThis:o||self).Box=t(o.Utils)})(this,function(c){function t(o,t){var e=void 0===(e=t.boxNoColorIcon)?"":e,i=void 0===(i=t.boxHasColorIcon)?"":i,t=(o=>{var t,e;if(o){if(c.isShallowObject(o))return t=
|
|
1
|
+
((o,t)=>{"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@ew-color-picker/utils")):"function"==typeof define&&define.amd?define(["@ew-color-picker/utils"],t):(o="undefined"!=typeof globalThis?globalThis:o||self).Box=t(o.Utils)})(this,function(c){function t(o,t){var e=void 0===(e=t.boxNoColorIcon)?"":e,i=void 0===(i=t.boxHasColorIcon)?"":i,s=void 0===(s=t.prefix)?c.DEFAULT_PREFIX:s,t=(o=>{var t,e;if(o){if(c.isShallowObject(o))return t=r(null!=(t=o.width)?t:32),e=r(null!=(e=o.height)?e:32),.5*Math.min(t,e);if(c.isNumber(o))return.5*o;if("string"==typeof o)return n[o]||16}return 16})(t.size);return o?i||c.arrowIcon("".concat(s,"color-picker-box-arrow-icon"),t,s):e||c.closeIcon("".concat(s,"color-picker-box-close-icon"),t,s)}var i=function(){return(i=Object.assign||function(o){for(var t,e=1,i=arguments.length;e<i;e++)for(var s in t=arguments[e])Object.prototype.hasOwnProperty.call(t,s)&&(o[s]=t[s]);return o}).apply(this,arguments)},e={mini:"20px",small:"24px",normal:"32px",medium:"36px",large:"40px"},n={mini:12,small:14,normal:16,medium:18,large:20},r=function(o){return!c.isNumber(o)&&(o=parseInt("".concat(o)),isNaN(o))?32:o};function o(o){var t=this;this.ewColorPicker=o,this.options={},this._handlers=[],this._hasBox=!0,this.box=null,this.hasColor=!1,this.handleOptions(),!1===this.options.hasBox&&(this._hasBox=!1),this.ewColorPicker.on&&"function"==typeof this.ewColorPicker.on&&this.ewColorPicker.on("change",function(o){t.setBoxBgColor(o)}),this.run()}return Object.defineProperty(o.prototype,"prefix",{get:function(){return c.getPrefix(this.ewColorPicker)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"hasBox",{get:function(){return this._hasBox},set:function(o){this._hasBox!==o&&((this._hasBox=o)?this.render():this.box&&this.box.parentNode&&(c.removeElement(this.box),this.box=null))},enumerable:!1,configurable:!0}),o.prototype.enableBox=function(o){this.hasBox=o=void 0===o?!0:o},o.prototype.handleOptions=function(){this.options=c.extend(this.options,this.ewColorPicker.options)},o.prototype.run=function(){this.render()},o.prototype.updateChildren=function(){var o;this.box&&(o=this.ewColorPicker.currentColor,this.hasColor=!!o,this.box.replaceChildren(c.createByTemplate(t(this.hasColor,this.options))))},o.prototype.destroy=function(){this.box&&(this.unbindHandler(),c.removeElement(this.box),this.box=null)},o.prototype.update=function(o){void 0===o&&(o=["defaultColor","size","disabled","readonly","className","style"]),this.box?(o.includes("defaultColor")&&(this.updateChildren(),this.setBoxBgColor(this.ewColorPicker.currentColor)),o.includes("size")&&this.setBoxSize(),(o.includes("disabled")||o.includes("readonly")||o.includes("className")||o.includes("style"))&&this.setBoxState()):this.render()},o.prototype.render=function(){var o,t=this.options,e=t.className,t=t.style;this.hasBox&&((o=this.ewColorPicker.getMountPoint("root"))?(this.box=c.$(".".concat(this.prefix,"color-picker-box"),o),this.box||(this.box=c.create("div"),c.addClass(this.box,"".concat(this.prefix,"color-picker-box")),e&&c.addClass(this.box,e),t&&c.setStyle(this.box,t),c.insertNode(o,this.box)),this.updateChildren(),this.setBoxSize(),this.setBoxBgColor(this.ewColorPicker.currentColor),this.setBoxState(),this.bindHandler()):c.warn("[ewColorPicker] Root mount point not found"))},o.prototype.setBoxSize=function(){var o,t;this.box&&(o=this.options.size,o=(o=o)?c.isShallowObject(o)?{width:o.width?c.isNumber(o.width)?"".concat(o.width,"px"):o.width:void 0,height:t=o.height?c.isNumber(o.height)?"".concat(o.height,"px"):o.height:void 0,lineHeight:t}:o?(t=void 0,{width:t=c.isNumber(o)?"".concat(o,"px"):"string"==typeof o?e[o]||o:"32px",height:t,lineHeight:t}):{}:{},0<Object.keys(o).length?c.setStyle(this.box,o):c.removeStyle(this.box,["width","height"]))},o.prototype.setBoxBgColor=function(o){var t,e;this.box&&(o&&""!==o.trim()?(t=(t=(t=o)&&c.colorToRgba(t))&&(e=c.parseRgbaString(t))?.5<.2126*(t=function(o){o=(o*e.a+255*(1-e.a))/255;return o<=.03928?o/12.92:Math.pow((.055+o)/1.055,2.4)})(e.r)+.7152*t(e.g)+.0722*t(e.b)?"#333333":"#ffffff":null,c.setStyle(this.box,i({backgroundColor:o,transition:"background-color 0.3s"},t?{color:t}:{}))):this.clearBoxBgColor())},o.prototype.clearBoxBgColor=function(){this.box&&c.removeStyle(this.box,["background-color","transition","color"])},o.prototype.setBoxState=function(){var o,t,e;this.box&&(o=(e=this.options).disabled,t=e.readonly,e=e.className,o?c.addClass(this.box,"is-disabled"):c.removeClass(this.box,"is-disabled"),t?c.addClass(this.box,"is-readonly"):c.removeClass(this.box,"is-readonly"),e)&&c.addClass(this.box,e)},o.prototype.bindHandler=function(){var o,t,e,i,s,n,r,l,h,a=this;this.box&&(o=this.options,t=o.onClick,e=o.onMouseEnter,i=o.onMouseLeave,s=o.disabled,n=o.readonly,r=o.togglePickerAnimation,l=o.pickerAnimationTime,c.on(this.box,"click",h=function(o){s||n?(o.preventDefault(),o.stopPropagation()):(a.ewColorPicker.pickerFlag?a.ewColorPicker.hidePanel(r,l):a.ewColorPicker.showPanel(r,l),null!=t&&t(a))}),this._handlers.push(function(){return c.off(a.box,"click",h)}),this.bindMouseEvents(e,i))},o.prototype.setDisabled=function(o){this.box&&(o?c.addClass(this.box,"is-disabled"):c.removeClass(this.box,"is-disabled"))},o.prototype.bindMouseEvents=function(o,t){var e,i,s=this;this.box&&(o&&(c.on(this.box,"mouseenter",e=function(){return o(s)}),this._handlers.push(function(){return c.off(s.box,"mouseenter",e)})),t)&&(c.on(this.box,"mouseleave",i=function(){return t(s)}),this._handlers.push(function(){return c.off(s.box,"mouseleave",i)}))},o.prototype.unbindHandler=function(){this._handlers.forEach(function(o){return o()}),this._handlers=[]},o.pluginName="ewColorPickerBox",o});
|
|
@@ -3,6 +3,7 @@ export declare const SIZE_MAP: Record<string, string>;
|
|
|
3
3
|
export declare const ICON_SIZE_MAP: Record<string, number>;
|
|
4
4
|
export declare const getBoxChildren: (hasColor: boolean, options: PartialBoxProps & {
|
|
5
5
|
size?: any;
|
|
6
|
+
prefix?: string;
|
|
6
7
|
}) => string;
|
|
7
8
|
export declare const getBoxIconColor: (color?: string) => string | null;
|
|
8
9
|
export declare const normalizeSize: (v: string | number) => number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const BOX_TEMPLATE: (children: string, style?: string, className?: string) => string;
|
|
1
|
+
export declare const BOX_TEMPLATE: (children: string, style?: string, className?: string, prefix?: string) => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ew-color-picker/box",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "box for ew-color-picker",
|
|
5
5
|
"main": "dist/box.min.js",
|
|
6
6
|
"module": "dist/box.esm.js",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"directory": "packages/box"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@ew-color-picker/core": "^2.0.
|
|
30
|
-
"@ew-color-picker/utils": "^2.0.
|
|
29
|
+
"@ew-color-picker/core": "^2.0.2",
|
|
30
|
+
"@ew-color-picker/utils": "^2.0.2"
|
|
31
31
|
},
|
|
32
32
|
"types": "dist/packages/box/src/index.d.ts",
|
|
33
33
|
"scripts": {
|