@ew-color-picker/box 2.0.4 → 2.0.5

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/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, DEFAULT_PREFIX, closeIcon, isShallowObject, isNumber, colorToRgba, parseRgbaString, extend, createByTemplate, removeElement, warn, $, create, addClass, setStyle, insertNode, removeStyle, removeClass, on, off, getPrefix } from '@ew-color-picker/utils';
6
+ import { arrowIcon, DEFAULT_PREFIX, closeIcon, isShallowObject, isNumber, isString, colorToRgba, parseRgbaString, 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.
@@ -111,7 +111,7 @@ var calculateIconSize = function (size) {
111
111
  // 数字形式
112
112
  return size * 0.5;
113
113
  }
114
- else if (typeof size === 'string') {
114
+ else if (isString(size)) {
115
115
  // 字符串形式:预设尺寸映射
116
116
  return ICON_SIZE_MAP[size] || 16;
117
117
  }
@@ -134,7 +134,7 @@ var processSizeConfig = function (size) {
134
134
  if (isNumber(size)) {
135
135
  val = "".concat(size, "px");
136
136
  }
137
- else if (typeof size === 'string') {
137
+ else if (isString(size)) {
138
138
  val = SIZE_MAP[size] || size;
139
139
  }
140
140
  else {
@@ -149,6 +149,8 @@ var ewColorPickerBoxPlugin = /** @class */ (function () {
149
149
  function ewColorPickerBoxPlugin(ewColorPicker) {
150
150
  var _this = this;
151
151
  this.ewColorPicker = ewColorPicker;
152
+ // 刻意不声明 applyOrder:缺省 0 保证 Box 先于所有 Post 插件初始化,
153
+ // Panel 挂载与自动定位依赖此时已存在的盒子 DOM。
152
154
  this.options = {};
153
155
  this._handlers = [];
154
156
  // 内部状态控制
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,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});
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(c.isString(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"):c.isString(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});
@@ -1,14 +1,14 @@
1
- import { PartialBoxProps } from "./type";
1
+ import { PartialBoxProps, BoxSize } from "./type";
2
2
  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
- size?: any;
5
+ size?: BoxSize;
6
6
  prefix?: string;
7
7
  }) => string;
8
8
  export declare const getBoxIconColor: (color?: string) => string | null;
9
9
  export declare const normalizeSize: (v: string | number) => number;
10
- export declare const calculateIconSize: (size?: any) => number;
11
- export declare const processSizeConfig: (size?: any) => {
10
+ export declare const calculateIconSize: (size?: BoxSize) => number;
11
+ export declare const processSizeConfig: (size?: BoxSize) => {
12
12
  width?: string;
13
13
  height?: string;
14
14
  lineHeight?: string;
@@ -15,3 +15,7 @@ export interface BoxProps {
15
15
  onMouseLeave?: (v: InstanceType<typeof ewColorPickerBoxPlugin>) => void;
16
16
  }
17
17
  export type PartialBoxProps = Partial<BoxProps>;
18
+ export type BoxSize = number | string | {
19
+ width?: number | string;
20
+ height?: number | string;
21
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ew-color-picker/box",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "box for ew-color-picker",
5
5
  "main": "dist/box.min.js",
6
6
  "module": "dist/box.esm.js",
@@ -31,8 +31,8 @@
31
31
  "directory": "packages/box"
32
32
  },
33
33
  "dependencies": {
34
- "@ew-color-picker/core": "^2.0.4",
35
- "@ew-color-picker/utils": "^2.0.4"
34
+ "@ew-color-picker/utils": "^2.0.5",
35
+ "@ew-color-picker/core": "^2.0.5"
36
36
  },
37
37
  "types": "dist/packages/box/src/index.d.ts",
38
38
  "scripts": {