@ew-color-picker/core 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
@@ -21,8 +21,8 @@ const picker = new ewColorPicker({ el: '#picker' })
21
21
 
22
22
  ## 相关链接
23
23
 
24
- - 核心概念:https://eveningwater.github.io/ew-color-picker/guide/concepts
25
- - 编写插件:https://eveningwater.github.io/ew-color-picker/guide/plugin-dev
24
+ - 核心概念:https://eveningwater.github.io/ew-color-picker/zh/guide/concepts
25
+ - 编写插件:https://eveningwater.github.io/ew-color-picker/zh/guide/plugin-dev
26
26
  - 源码仓库:https://github.com/eveningwater/ew-color-picker
27
27
 
28
28
  ## License
package/dist/core.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 { extend, checkContainer, isUndefined, isNull, warn, isHTMLElement, isString, isObject, tryErrorHandler, colorToRgba, colorRgbaToHex, colorRgbaToHsva, create, setAttr, insertNode, addClass, isFunction, getAnimationType, open, on, close, setStyle, off, removeElement, EventEmitter } from '@ew-color-picker/utils';
6
+ import { extend, checkContainer, DEFAULT_PREFIX, ApplyOrder, isUndefined, isNull, warn, isHTMLElement, isString, isObject, tryErrorHandler, colorToRgba, colorRgbaToHex, colorRgbaToHsva, create, setAttr, insertNode, addClass, isFunction, getAnimationType, open, on, close, setStyle, off, removeElement, EventEmitter } from '@ew-color-picker/utils';
7
7
 
8
8
  /******************************************************************************
9
9
  Copyright (c) Microsoft Corporation.
@@ -88,6 +88,7 @@ var defaultConfig = {
88
88
  pickerAnimationTime: 200,
89
89
  autoPanelPosition: false,
90
90
  panelPlacement: "bottom",
91
+ prefix: DEFAULT_PREFIX,
91
92
  sure: function () { },
92
93
  clear: function () { },
93
94
  togglePicker: function () { },
@@ -107,7 +108,8 @@ var ewColorPickerMergeOptions = /** @class */ (function (_super) {
107
108
  }
108
109
  ewColorPickerMergeOptions.prototype.merge = function (options, pluginNameProp) {
109
110
  var _a = options || {}, el = _a.el, rest = __rest(_a, ["el"]);
110
- return extend({}, defaultConfig, __assign(__assign(__assign({}, rest), { el: checkContainer(el) }), pluginNameProp));
111
+ // pluginNameProp 只作为插件开关的默认值,用户传入的同名配置必须优先
112
+ return extend({}, defaultConfig, pluginNameProp !== null && pluginNameProp !== void 0 ? pluginNameProp : {}, __assign(__assign({}, rest), { el: checkContainer(el) }));
111
113
  };
112
114
  ewColorPickerMergeOptions.prototype.bindOptions = function (options, pluginNameProp) {
113
115
  if (pluginNameProp === void 0) { pluginNameProp = {}; }
@@ -143,8 +145,8 @@ var getMountOrderMap = function () {
143
145
  };
144
146
  // 应用顺序映射
145
147
  var APPLY_ORDER_MAP = (_a = {},
146
- _a["pre" /* ApplyOrder.Pre */] = -1,
147
- _a["post" /* ApplyOrder.Post */] = 1,
148
+ _a[ApplyOrder.Pre] = -1,
149
+ _a[ApplyOrder.Post] = 1,
148
150
  _a);
149
151
  // 事件类型
150
152
  var EVENT_TYPES = [
@@ -179,7 +181,8 @@ var ewColorPicker = /** @class */ (function (_super) {
179
181
  if (panelContainer && panelContainer.contains(target))
180
182
  return;
181
183
  // 如果点击的是颜色盒子,不关闭(避免与盒子切换逻辑冲突)
182
- var colorBox = rootElement === null || rootElement === void 0 ? void 0 : rootElement.querySelector(".ew-color-picker-box");
184
+ var prefix = _this.options.prefix || DEFAULT_PREFIX;
185
+ var colorBox = rootElement === null || rootElement === void 0 ? void 0 : rootElement.querySelector(".".concat(prefix, "color-picker-box"));
183
186
  if (colorBox && colorBox.contains(target))
184
187
  return;
185
188
  // 点击面板和盒子之外的区域,关闭面板
@@ -203,15 +206,15 @@ var ewColorPicker = /** @class */ (function (_super) {
203
206
  // 插件注册方法
204
207
  ewColorPicker.use = function (ctor) {
205
208
  var pluginName = ctor.pluginName;
206
- // 检查插件是否已安装
207
- if (ewColorPicker.plugins.some(function (plugin) { return ctor === plugin.ctor; })) {
208
- return ewColorPicker;
209
- }
210
209
  // 验证插件名称
211
210
  if (isUndefined(pluginName) || isNull(pluginName)) {
212
211
  warn("[ewColorPicker warning]: Plugin Class must specify plugin's name in static property by 'pluginName' field.");
213
212
  return ewColorPicker;
214
213
  }
214
+ // 按 pluginName 去重,避免 HMR 或多入口重复注册同一个插件
215
+ if (ewColorPicker.plugins.some(function (plugin) { return plugin.name === pluginName || ctor === plugin.ctor; })) {
216
+ return ewColorPicker;
217
+ }
215
218
  // 注册插件
216
219
  ewColorPicker.pluginsMap[pluginName] = true;
217
220
  ewColorPicker.plugins.push({
@@ -313,10 +316,11 @@ var ewColorPicker = /** @class */ (function (_super) {
313
316
  this.pickerFlag = false;
314
317
  };
315
318
  ewColorPicker.prototype.createMountPoints = function () {
319
+ var prefix = this.options.prefix || DEFAULT_PREFIX;
316
320
  // 创建主容器
317
321
  var rootElement = create("div");
318
322
  setAttr(rootElement, {
319
- class: "ew-color-picker",
323
+ class: "".concat(prefix, "color-picker"),
320
324
  "data-uid": this._color_picker_uid,
321
325
  });
322
326
  insertNode(this.getContainer(), rootElement);
@@ -325,8 +329,8 @@ var ewColorPicker = /** @class */ (function (_super) {
325
329
  this.wrapper.isEwColorPickerContainer = true;
326
330
  // 创建面板容器(默认隐藏)
327
331
  var panelContainer = create("div");
328
- setAttr(panelContainer, { class: "ew-color-picker-panel-container" });
329
- addClass(panelContainer, "ew-color-picker-panel-container-hidden");
332
+ setAttr(panelContainer, { class: "".concat(prefix, "color-picker-panel-container") });
333
+ addClass(panelContainer, "".concat(prefix, "color-picker-panel-container-hidden"));
330
334
  insertNode(rootElement, panelContainer);
331
335
  // 设置挂载点
332
336
  this.mountPoints.set("root", rootElement);
@@ -437,8 +441,8 @@ var ewColorPicker = /** @class */ (function (_super) {
437
441
  .then(function () {
438
442
  if (_this.isDestroyed)
439
443
  return;
440
- // 重置自动定位样式
441
- if (autoPanelPosition && hasBox) {
444
+ // 重置自动定位样式(面板被挂载到外部容器时由 Panel 插件负责定位,不能重置)
445
+ if (autoPanelPosition && hasBox && !_this.options.appendTo) {
442
446
  setStyle(panelContainer, {
443
447
  position: "absolute",
444
448
  left: "0",
@@ -488,6 +492,9 @@ var ewColorPicker = /** @class */ (function (_super) {
488
492
  if (isFunction(ctor)) {
489
493
  _this.plugins[name] = new ctor(_this);
490
494
  }
495
+ }, function (error) {
496
+ // 插件构造失败必须始终可见,不能依赖 true 开关
497
+ console.warn("[ewColorPicker warning]: Failed to apply plugin '".concat(name, "': ").concat(error));
491
498
  });
492
499
  });
493
500
  };
package/dist/core.min.js CHANGED
@@ -1 +1 @@
1
- ((o,e)=>{"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@ew-color-picker/utils")):"function"==typeof define&&define.amd?define(["exports","@ew-color-picker/utils"],e):e((o="undefined"!=typeof globalThis?globalThis:o||self).Core={},o.Utils)})(this,function(o,c){var n=function(o,e){return(n=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(o,e){o.__proto__=e}:function(o,e){for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(o[t]=e[t])}))(o,e)};function e(o,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function t(){this.constructor=o}n(o,e),o.prototype=null===e?Object.create(e):(t.prototype=e.prototype,new t)}var i=function(){return(i=Object.assign||function(o){for(var e,t=1,n=arguments.length;t<n;t++)for(var i in e=arguments[t])Object.prototype.hasOwnProperty.call(e,i)&&(o[i]=e[i]);return o}).apply(this,arguments)};function r(o,e){var t={};for(i in o)Object.prototype.hasOwnProperty.call(o,i)&&e.indexOf(i)<0&&(t[i]=o[i]);if(null!=o&&"function"==typeof Object.getOwnPropertySymbols)for(var n=0,i=Object.getOwnPropertySymbols(o);n<i.length;n++)e.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(o,i[n])&&(t[i[n]]=o[i[n]]);return t}function l(o,e,t){if(t||2===arguments.length)for(var n,i=0,r=e.length;i<r;i++)!n&&i in e||((n=n||Array.prototype.slice.call(e,0,i))[i]=e[i]);return o.concat(n||Array.prototype.slice.call(e))}var t,s,u={disabled:!1,predefineColor:[],size:"normal",defaultColor:"",isClickOutside:!0,hueDirection:"vertical",alphaDirection:"vertical",clearText:"清空",sureText:"确定",togglePickerAnimation:"default",pickerAnimationTime:200,autoPanelPosition:!1,panelPlacement:"bottom",sure:function(){},clear:function(){},togglePicker:function(){},changeColor:function(){}},a=(e(p,t=function(){}),p.prototype.merge=function(o,e){var o=o||{},t=o.el,o=r(o,["el"]);return c.extend({},u,i(i(i({},o),{el:c.checkContainer(t)}),e))},p.prototype.bindOptions=function(o,e){var t,n=this.merge(o,e=void 0===e?{}:e);for(t in n){var i=n[t];this[t]=i}return this},p);function p(){var o=t.call(this)||this;return o.el=document.body,o}(s={}).pre=-1,s.post=1;var h,g=s,f=["destroy","change","sure","clear","toggle","options-update","mode-change"],d=(e(P,h=c.EventEmitter),P.use=function(e){var o=e.pluginName;return P.plugins.some(function(o){return e===o.ctor})||(c.isUndefined(o)||c.isNull(o)?c.warn("[ewColorPicker warning]: Plugin Class must specify plugin's name in static property by 'pluginName' field."):(P.pluginsMap[o]=!0,P.plugins.push({name:o,applyOrder:e.applyOrder,ctor:e}))),P},P.prototype.normalizeOptions=function(o,e){var t,n;return c.isHTMLElement(o)||c.isString(o)?(t=e?(e.el,e=r(e,["el"]),i({el:o},e)):{el:o},this.shouldAutoMount=!0):c.isObject(t=o)&&t.el&&(this.shouldAutoMount=!0),(new a).bindOptions(t,(n={},d.plugins.forEach(function(o){n[o.name]=!0}),n))},P.prototype.init=function(){var o=this;c.tryErrorHandler(function(){o.plugins={},o._color_picker_uid=o.generateUID(),o.initCoreProperties()})},P.prototype.initCoreProperties=function(){var o,e,t=this.options,n=t.defaultColor,i=t.alphaDirection,t=t.hueDirection;n?(o=n,(null==(e=this.plugins)?void 0:e.ewColorPickerAlpha)?n.startsWith("#")&&(o=c.colorToRgba(n)):n.startsWith("rgba")&&(o=c.colorRgbaToHex(n)),this.currentColor=o,e=(e=c.colorToRgba(o))||"rgba(255, 0, 0, 1)",n=c.colorRgbaToHsva(e),isNaN(n.h)?this.hsvaColor={h:0,s:100,v:100,a:1}:this.hsvaColor=n):(this.currentColor="",this.hsvaColor={h:0,s:0,v:0,a:0}),this.panelWidth=0,this.panelHeight=0,this.panelLeft=0,this.panelTop=0,this.isHueHorizontal="horizontal"===t,this.isAlphaHorizontal="horizontal"===i,this.colorMode=["Hex","RGB","HSV"],this.currentMode="Hex",this.pickerFlag=!1},P.prototype.createMountPoints=function(){var o=c.create("div"),e=(c.setAttr(o,{class:"ew-color-picker","data-uid":this._color_picker_uid}),c.insertNode(this.getContainer(),o),this.wrapper=o,this.wrapper.isEwColorPickerContainer=!0,c.create("div"));c.setAttr(e,{class:"ew-color-picker-panel-container"}),c.addClass(e,"ew-color-picker-panel-container-hidden"),c.insertNode(o,e),this.mountPoints.set("root",o),this.mountPoints.set("panelContainer",e)},P.prototype.getMountPoint=function(o){if(!this.isDestroyed)return this.mountPoints.get(o)},P.prototype.getContainer=function(){return this.options.el},P.prototype.mount=function(o){return this.isDestroyed||(o=o?c.checkContainer(o):this.options.el||document.body,this.options.el=o,this.createMountPoints(),this.applyPlugins(),this.notifyHuePluginUpdate(this.hsvaColor.h)),this},P.prototype.reapplyPlugins=function(){Object.values(this.plugins).forEach(function(o){c.isFunction(o.run)&&o.run()})},P.prototype.showPanel=function(o,e){var t,n,i,r,s=this;this.isDestroyed||(t=this.mountPoints.get("panelContainer"))&&(n=(r=this.options||{}).pickerAnimationTime,i=r.togglePicker,this.currentColor||(this.currentColor=r=r.defaultColor||"#ff0000",r=(r=c.colorToRgba(r))||"rgba(255, 0, 0, 1)",r=c.colorRgbaToHsva(r),this.hsvaColor=r,isNaN(r.h))||this.notifyHuePluginUpdate(r.h),r=o||c.getAnimationType(this),c.open(r,t,e||n||200).then(function(){s.pickerFlag=!0,s.trigger("toggle",!0),c.isFunction(i)&&i(!0),s.syncAllPlugins(s.currentColor),setTimeout(function(){var o=s.plugins.ewColorPickerPanel;o&&c.isFunction(o.handleAutoPosition)&&o.handleAutoPosition.call(o),c.on(document,"mousedown",s._onDocumentClick,{capture:!0})},0)}).catch(function(o){c.warn("[ewColorPicker error]: Failed to show panel: ".concat(o))}))},P.prototype.hidePanel=function(o,e){var t,n,i,r,s,l,u=this;this.isDestroyed||(t=this.mountPoints.get("panelContainer"))&&(n=(l=this.options||{}).pickerAnimationTime,i=l.togglePicker,r=l.autoPanelPosition,s=this.plugins.ewColorPickerBox||!1,l=o||c.getAnimationType(this),c.close(l,t,e||n||200).then(function(){u.isDestroyed||(r&&s&&c.setStyle(t,{position:"absolute",left:"0",top:"100%",visibility:"visible"}),u.pickerFlag=!1,u.trigger("toggle",!1),c.isFunction(i)&&i(!1),c.off(document,"mousedown",u._onDocumentClick,{capture:!0}))}).catch(function(o){c.warn("[ewColorPicker error]: Failed to hide panel: ".concat(o))}))},P.prototype.generateUID=function(){return"ew-color-picker-".concat(Date.now(),"-").concat(Math.random().toString(36).substring(2,11))},P.prototype.applyPlugins=function(){var n=this,o=l([],P.plugins,!0).sort(function(o,e){var t,n,i=o.applyOrder?g[o.applyOrder]:0,r=e.applyOrder?g[e.applyOrder]:0;return i!==r?i-r:(t={},n=0,d.plugins.forEach(function(o){t[o.name]=n++}),((i=t)[o.name]||999)-(i[e.name]||999))});this.checkPluginDependencies(),o.forEach(function(o){var e=o.ctor,t=o.name;c.tryErrorHandler(function(){c.isFunction(e)&&(n.plugins[t]=new e(n))})})},P.prototype.checkPluginDependencies=function(){var t=this;Object.entries({hue:["ewColorPickerHue"],alpha:["ewColorPickerAlpha"],panel:["ewColorPickerPanel"],input:["ewColorPickerInput"],inputNumber:["ewColorPickerInputNumber"],button:["ewColorPickerButton"],predefine:["ewColorPickerPredefine"],colorMode:["ewColorPickerColorMode"],box:["ewColorPickerBox"],console:["ewColorPickerConsole"]}).forEach(function(o){var e=o[0],o=o[1];t.options[e]&&o.forEach(function(o){P.pluginsMap[o]||c.warn("[ewColorPicker warning]: Plugin '".concat(o,"' is required but not injected. Please use ewColorPicker.use(").concat(o,") to register the plugin."))})}),this.checkSpecificFeatureDependencies()},P.prototype.checkSpecificFeatureDependencies=function(){this.options.hueDirection&&!P.pluginsMap.ewColorPickerHue&&c.warn("[ewColorPicker warning]: hueDirection is configured but ewColorPickerHue plugin is not injected. Please use ewColorPicker.use(HuePlugin) to register the plugin."),this.options.alphaDirection&&!P.pluginsMap.ewColorPickerAlpha&&c.warn("[ewColorPicker warning]: alphaDirection is configured but ewColorPickerAlpha plugin is not injected. Please use ewColorPicker.use(AlphaPlugin) to register the plugin."),this.options.predefineColor&&0<this.options.predefineColor.length&&!P.pluginsMap.ewColorPickerPredefine&&c.warn("[ewColorPicker warning]: predefineColor is configured but ewColorPickerPredefine plugin is not injected. Please use ewColorPicker.use(PredefinePlugin) to register the plugin."),P.pluginsMap.ewColorPickerColorMode&&!P.pluginsMap.ewColorPickerInputNumber&&c.warn("[ewColorPicker warning]: Color mode plugin requires InputNumber plugin. color-mode plugin requires InputNumber plugin. Please use ewColorPicker.use(InputNumberPlugin) to register the plugin."),P.pluginsMap.ewColorPickerPanel||c.warn("[ewColorPicker warning]: Panel plugin is required as core plugin but not injected. Please use ewColorPicker.use(PanelPlugin) to register the plugin.")},P.prototype.syncAllPlugins=function(e){Object.values(this.plugins).forEach(function(o){c.isFunction(o.syncColor)&&o.syncColor(e)})},P.prototype.updateOptions=function(o){this.isDestroyed||(this.options=c.extend({},this.options,o),o=(this.options||{}).defaultColor,c.isUndefined(o)||(c.colorToRgba(o)?this.setColor(o):c.warn("[ewColorPicker warning]: Invalid defaultColor '".concat(o,"', keep current color unchanged."))),this.reapplyPlugins(),this.trigger("options-update",this.options))},P.prototype.openPicker=function(){this.showPanel()},P.prototype.closePicker=function(){this.hidePanel()},P.prototype.destroy=function(){var o=this;this.isDestroyed||(this.isDestroyed=!0,c.off(document,"mousedown",this._onDocumentClick,{capture:!0}),this.plugins&&Object.values(this.plugins).forEach(function(o){c.tryErrorHandler(function(){c.isFunction(null==o?void 0:o.destroy)&&o.destroy()})}),this.mountPoints.forEach(function(o){c.tryErrorHandler(function(){c.removeElement(o)})}),this.mountPoints.clear(),c.tryErrorHandler(function(){c.removeElement(o.wrapper)}),this.plugins={},this.trigger("destroy"))},P.prototype.setColor=function(o){var e;(this.currentColor=o)&&(e=c.colorToRgba(o),this.hsvaColor=e?c.colorRgbaToHsva(e):{h:0,s:100,v:100,a:1}),this.trigger("change",o),c.isFunction(null==(e=this.options)?void 0:e.changeColor)&&this.options.changeColor(o)},P.prototype.getColor=function(){return this.currentColor},P.prototype.getHsvaColor=function(){return i({},this.hsvaColor)},P.prototype.setHsvaColor=function(o){this.hsvaColor=i({},o)},P.prototype.getDestroyedStatus=function(){return this.isDestroyed},P.prototype.use=function(o){return c.isFunction(o.install)&&o.install(this),this},P.prototype.emit=function(o){for(var e=[],t=1;t<arguments.length;t++)e[t-1]=arguments[t];this.trigger.apply(this,l([o],e,!1));var n=this.options||{},i=n.clear,r=n.sure,s=n.togglePicker;switch(o){case"clear":c.isFunction(i)&&i();break;case"sure":c.isFunction(r)&&r();break;case"toggle":c.isFunction(s)&&s.apply(void 0,e)}},P.prototype.on=function(o,e,t){return h.prototype.on.call(this,o,e,t),this},P.prototype.off=function(o,e){return h.prototype.off.call(this,o,e),this},P.prototype.getOptions=function(){return this.options},P.prototype.notifyHuePluginUpdate=function(o){var e=null==(e=this.plugins)?void 0:e.ewColorPickerHue;c.isFunction(null==e?void 0:e.updateHueThumbPosition)&&e.updateHueThumbPosition(o)},P.plugins=[],P.pluginsMap={},P);function P(o,e){var n=h.call(this,f)||this;return n.mountPoints=new Map,n.isDestroyed=!1,n.shouldAutoMount=!1,n._onDocumentClick=function(o){var e,t;n.isDestroyed||!n.options.isClickOutside||(t=n.mountPoints.get("panelContainer"),e=n.mountPoints.get("root"),o=o.target,t&&t.contains(o))||(t=null==e?void 0:e.querySelector(".ew-color-picker-box"))&&t.contains(o)||(t=(e=n.options).togglePickerAnimation,n.hidePanel(t,e.pickerAnimationTime))},n.options=n.normalizeOptions(o,e),n.init(),n.shouldAutoMount&&n.options.el&&c.tryErrorHandler(function(){n.mount(n.options.el)},function(o){c.warn("[ewColorPicker warning]: Auto mount failed: ".concat(o))}),n}o.DEFAULT_ANIMATION_TIME=200,o.default=d,Object.defineProperty(o,"__esModule",{value:!0})});
1
+ ((o,e)=>{"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@ew-color-picker/utils")):"function"==typeof define&&define.amd?define(["exports","@ew-color-picker/utils"],e):e((o="undefined"!=typeof globalThis?globalThis:o||self).Core={},o.Utils)})(this,function(o,u){var n=function(o,e){return(n=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(o,e){o.__proto__=e}:function(o,e){for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(o[t]=e[t])}))(o,e)};function e(o,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function t(){this.constructor=o}n(o,e),o.prototype=null===e?Object.create(e):(t.prototype=e.prototype,new t)}var i=function(){return(i=Object.assign||function(o){for(var e,t=1,n=arguments.length;t<n;t++)for(var i in e=arguments[t])Object.prototype.hasOwnProperty.call(e,i)&&(o[i]=e[i]);return o}).apply(this,arguments)};function r(o,e){var t={};for(i in o)Object.prototype.hasOwnProperty.call(o,i)&&e.indexOf(i)<0&&(t[i]=o[i]);if(null!=o&&"function"==typeof Object.getOwnPropertySymbols)for(var n=0,i=Object.getOwnPropertySymbols(o);n<i.length;n++)e.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(o,i[n])&&(t[i[n]]=o[i[n]]);return t}function l(o,e,t){if(t||2===arguments.length)for(var n,i=0,r=e.length;i<r;i++)!n&&i in e||((n=n||Array.prototype.slice.call(e,0,i))[i]=e[i]);return o.concat(n||Array.prototype.slice.call(e))}var t,s,c={disabled:!1,predefineColor:[],size:"normal",defaultColor:"",isClickOutside:!0,hueDirection:"vertical",alphaDirection:"vertical",clearText:"清空",sureText:"确定",togglePickerAnimation:"default",pickerAnimationTime:200,autoPanelPosition:!1,panelPlacement:"bottom",prefix:u.DEFAULT_PREFIX,sure:function(){},clear:function(){},togglePicker:function(){},changeColor:function(){}},a=(e(p,t=function(){}),p.prototype.merge=function(o,e){var o=o||{},t=o.el,o=r(o,["el"]);return u.extend({},c,null!=e?e:{},i(i({},o),{el:u.checkContainer(t)}))},p.prototype.bindOptions=function(o,e){var t,n=this.merge(o,e=void 0===e?{}:e);for(t in n){var i=n[t];this[t]=i}return this},p);function p(){var o=t.call(this)||this;return o.el=document.body,o}(s={})[u.ApplyOrder.Pre]=-1,s[u.ApplyOrder.Post]=1;var h,g=s,f=["destroy","change","sure","clear","toggle","options-update","mode-change"],d=(e(P,h=u.EventEmitter),P.use=function(e){var t=e.pluginName;return u.isUndefined(t)||u.isNull(t)?u.warn("[ewColorPicker warning]: Plugin Class must specify plugin's name in static property by 'pluginName' field."):P.plugins.some(function(o){return o.name===t||e===o.ctor})||(P.pluginsMap[t]=!0,P.plugins.push({name:t,applyOrder:e.applyOrder,ctor:e})),P},P.prototype.normalizeOptions=function(o,e){var t,n;return u.isHTMLElement(o)||u.isString(o)?(t=e?(e.el,e=r(e,["el"]),i({el:o},e)):{el:o},this.shouldAutoMount=!0):u.isObject(t=o)&&t.el&&(this.shouldAutoMount=!0),(new a).bindOptions(t,(n={},d.plugins.forEach(function(o){n[o.name]=!0}),n))},P.prototype.init=function(){var o=this;u.tryErrorHandler(function(){o.plugins={},o._color_picker_uid=o.generateUID(),o.initCoreProperties()})},P.prototype.initCoreProperties=function(){var o,e,t=this.options,n=t.defaultColor,i=t.alphaDirection,t=t.hueDirection;n?(o=n,(null==(e=this.plugins)?void 0:e.ewColorPickerAlpha)?n.startsWith("#")&&(o=u.colorToRgba(n)):n.startsWith("rgba")&&(o=u.colorRgbaToHex(n)),this.currentColor=o,e=(e=u.colorToRgba(o))||"rgba(255, 0, 0, 1)",n=u.colorRgbaToHsva(e),isNaN(n.h)?this.hsvaColor={h:0,s:100,v:100,a:1}:this.hsvaColor=n):(this.currentColor="",this.hsvaColor={h:0,s:0,v:0,a:0}),this.panelWidth=0,this.panelHeight=0,this.panelLeft=0,this.panelTop=0,this.isHueHorizontal="horizontal"===t,this.isAlphaHorizontal="horizontal"===i,this.colorMode=["Hex","RGB","HSV"],this.currentMode="Hex",this.pickerFlag=!1},P.prototype.createMountPoints=function(){var o=this.options.prefix||u.DEFAULT_PREFIX,e=u.create("div"),t=(u.setAttr(e,{class:"".concat(o,"color-picker"),"data-uid":this._color_picker_uid}),u.insertNode(this.getContainer(),e),this.wrapper=e,this.wrapper.isEwColorPickerContainer=!0,u.create("div"));u.setAttr(t,{class:"".concat(o,"color-picker-panel-container")}),u.addClass(t,"".concat(o,"color-picker-panel-container-hidden")),u.insertNode(e,t),this.mountPoints.set("root",e),this.mountPoints.set("panelContainer",t)},P.prototype.getMountPoint=function(o){if(!this.isDestroyed)return this.mountPoints.get(o)},P.prototype.getContainer=function(){return this.options.el},P.prototype.mount=function(o){return this.isDestroyed||(o=o?u.checkContainer(o):this.options.el||document.body,this.options.el=o,this.createMountPoints(),this.applyPlugins(),this.notifyHuePluginUpdate(this.hsvaColor.h)),this},P.prototype.reapplyPlugins=function(){Object.values(this.plugins).forEach(function(o){u.isFunction(o.run)&&o.run()})},P.prototype.showPanel=function(o,e){var t,n,i,r,s=this;this.isDestroyed||(t=this.mountPoints.get("panelContainer"))&&(n=(r=this.options||{}).pickerAnimationTime,i=r.togglePicker,this.currentColor||(this.currentColor=r=r.defaultColor||"#ff0000",r=(r=u.colorToRgba(r))||"rgba(255, 0, 0, 1)",r=u.colorRgbaToHsva(r),this.hsvaColor=r,isNaN(r.h))||this.notifyHuePluginUpdate(r.h),r=o||u.getAnimationType(this),u.open(r,t,e||n||200).then(function(){s.pickerFlag=!0,s.trigger("toggle",!0),u.isFunction(i)&&i(!0),s.syncAllPlugins(s.currentColor),setTimeout(function(){var o=s.plugins.ewColorPickerPanel;o&&u.isFunction(o.handleAutoPosition)&&o.handleAutoPosition.call(o),u.on(document,"mousedown",s._onDocumentClick,{capture:!0})},0)}).catch(function(o){u.warn("[ewColorPicker error]: Failed to show panel: ".concat(o))}))},P.prototype.hidePanel=function(o,e){var t,n,i,r,s,l,c=this;this.isDestroyed||(t=this.mountPoints.get("panelContainer"))&&(n=(l=this.options||{}).pickerAnimationTime,i=l.togglePicker,r=l.autoPanelPosition,s=this.plugins.ewColorPickerBox||!1,l=o||u.getAnimationType(this),u.close(l,t,e||n||200).then(function(){c.isDestroyed||(r&&s&&!c.options.appendTo&&u.setStyle(t,{position:"absolute",left:"0",top:"100%",visibility:"visible"}),c.pickerFlag=!1,c.trigger("toggle",!1),u.isFunction(i)&&i(!1),u.off(document,"mousedown",c._onDocumentClick,{capture:!0}))}).catch(function(o){u.warn("[ewColorPicker error]: Failed to hide panel: ".concat(o))}))},P.prototype.generateUID=function(){return"ew-color-picker-".concat(Date.now(),"-").concat(Math.random().toString(36).substring(2,11))},P.prototype.applyPlugins=function(){var n=this,o=l([],P.plugins,!0).sort(function(o,e){var t,n,i=o.applyOrder?g[o.applyOrder]:0,r=e.applyOrder?g[e.applyOrder]:0;return i!==r?i-r:(t={},n=0,d.plugins.forEach(function(o){t[o.name]=n++}),((i=t)[o.name]||999)-(i[e.name]||999))});this.checkPluginDependencies(),o.forEach(function(o){var e=o.ctor,t=o.name;u.tryErrorHandler(function(){u.isFunction(e)&&(n.plugins[t]=new e(n))},function(o){console.warn("[ewColorPicker warning]: Failed to apply plugin '".concat(t,"': ").concat(o))})})},P.prototype.checkPluginDependencies=function(){var t=this;Object.entries({hue:["ewColorPickerHue"],alpha:["ewColorPickerAlpha"],panel:["ewColorPickerPanel"],input:["ewColorPickerInput"],inputNumber:["ewColorPickerInputNumber"],button:["ewColorPickerButton"],predefine:["ewColorPickerPredefine"],colorMode:["ewColorPickerColorMode"],box:["ewColorPickerBox"],console:["ewColorPickerConsole"]}).forEach(function(o){var e=o[0],o=o[1];t.options[e]&&o.forEach(function(o){P.pluginsMap[o]||u.warn("[ewColorPicker warning]: Plugin '".concat(o,"' is required but not injected. Please use ewColorPicker.use(").concat(o,") to register the plugin."))})}),this.checkSpecificFeatureDependencies()},P.prototype.checkSpecificFeatureDependencies=function(){this.options.hueDirection&&!P.pluginsMap.ewColorPickerHue&&u.warn("[ewColorPicker warning]: hueDirection is configured but ewColorPickerHue plugin is not injected. Please use ewColorPicker.use(HuePlugin) to register the plugin."),this.options.alphaDirection&&!P.pluginsMap.ewColorPickerAlpha&&u.warn("[ewColorPicker warning]: alphaDirection is configured but ewColorPickerAlpha plugin is not injected. Please use ewColorPicker.use(AlphaPlugin) to register the plugin."),this.options.predefineColor&&0<this.options.predefineColor.length&&!P.pluginsMap.ewColorPickerPredefine&&u.warn("[ewColorPicker warning]: predefineColor is configured but ewColorPickerPredefine plugin is not injected. Please use ewColorPicker.use(PredefinePlugin) to register the plugin."),P.pluginsMap.ewColorPickerColorMode&&!P.pluginsMap.ewColorPickerInputNumber&&u.warn("[ewColorPicker warning]: Color mode plugin requires InputNumber plugin. color-mode plugin requires InputNumber plugin. Please use ewColorPicker.use(InputNumberPlugin) to register the plugin."),P.pluginsMap.ewColorPickerPanel||u.warn("[ewColorPicker warning]: Panel plugin is required as core plugin but not injected. Please use ewColorPicker.use(PanelPlugin) to register the plugin.")},P.prototype.syncAllPlugins=function(e){Object.values(this.plugins).forEach(function(o){u.isFunction(o.syncColor)&&o.syncColor(e)})},P.prototype.updateOptions=function(o){this.isDestroyed||(this.options=u.extend({},this.options,o),o=(this.options||{}).defaultColor,u.isUndefined(o)||(u.colorToRgba(o)?this.setColor(o):u.warn("[ewColorPicker warning]: Invalid defaultColor '".concat(o,"', keep current color unchanged."))),this.reapplyPlugins(),this.trigger("options-update",this.options))},P.prototype.openPicker=function(){this.showPanel()},P.prototype.closePicker=function(){this.hidePanel()},P.prototype.destroy=function(){var o=this;this.isDestroyed||(this.isDestroyed=!0,u.off(document,"mousedown",this._onDocumentClick,{capture:!0}),this.plugins&&Object.values(this.plugins).forEach(function(o){u.tryErrorHandler(function(){u.isFunction(null==o?void 0:o.destroy)&&o.destroy()})}),this.mountPoints.forEach(function(o){u.tryErrorHandler(function(){u.removeElement(o)})}),this.mountPoints.clear(),u.tryErrorHandler(function(){u.removeElement(o.wrapper)}),this.plugins={},this.trigger("destroy"))},P.prototype.setColor=function(o){var e;(this.currentColor=o)&&(e=u.colorToRgba(o),this.hsvaColor=e?u.colorRgbaToHsva(e):{h:0,s:100,v:100,a:1}),this.trigger("change",o),u.isFunction(null==(e=this.options)?void 0:e.changeColor)&&this.options.changeColor(o)},P.prototype.getColor=function(){return this.currentColor},P.prototype.getHsvaColor=function(){return i({},this.hsvaColor)},P.prototype.setHsvaColor=function(o){this.hsvaColor=i({},o)},P.prototype.getDestroyedStatus=function(){return this.isDestroyed},P.prototype.use=function(o){return u.isFunction(o.install)&&o.install(this),this},P.prototype.emit=function(o){for(var e=[],t=1;t<arguments.length;t++)e[t-1]=arguments[t];this.trigger.apply(this,l([o],e,!1));var n=this.options||{},i=n.clear,r=n.sure,s=n.togglePicker;switch(o){case"clear":u.isFunction(i)&&i();break;case"sure":u.isFunction(r)&&r();break;case"toggle":u.isFunction(s)&&s.apply(void 0,e)}},P.prototype.on=function(o,e,t){return h.prototype.on.call(this,o,e,t),this},P.prototype.off=function(o,e){return h.prototype.off.call(this,o,e),this},P.prototype.getOptions=function(){return this.options},P.prototype.notifyHuePluginUpdate=function(o){var e=null==(e=this.plugins)?void 0:e.ewColorPickerHue;u.isFunction(null==e?void 0:e.updateHueThumbPosition)&&e.updateHueThumbPosition(o)},P.plugins=[],P.pluginsMap={},P);function P(o,e){var n=h.call(this,f)||this;return n.mountPoints=new Map,n.isDestroyed=!1,n.shouldAutoMount=!1,n._onDocumentClick=function(o){var e,t;n.isDestroyed||!n.options.isClickOutside||(e=n.mountPoints.get("panelContainer"),t=n.mountPoints.get("root"),o=o.target,e&&e.contains(o))||(e=n.options.prefix||u.DEFAULT_PREFIX,(t=null==t?void 0:t.querySelector(".".concat(e,"color-picker-box")))&&t.contains(o))||(t=(e=n.options).togglePickerAnimation,n.hidePanel(t,e.pickerAnimationTime))},n.options=n.normalizeOptions(o,e),n.init(),n.shouldAutoMount&&n.options.el&&u.tryErrorHandler(function(){n.mount(n.options.el)},function(o){u.warn("[ewColorPicker warning]: Auto mount failed: ".concat(o))}),n}o.DEFAULT_ANIMATION_TIME=200,o.default=d,Object.defineProperty(o,"__esModule",{value:!0})});
@@ -22,6 +22,8 @@ export interface ewColorPickerOptions {
22
22
  togglePickerAnimation?: string;
23
23
  pickerAnimationTime?: number;
24
24
  autoPanelPosition?: boolean;
25
+ appendTo?: string | HTMLElement;
26
+ prefix?: string;
25
27
  panelPlacement?: 'top-start' | 'top' | 'top-end' | 'left-start' | 'left' | 'left-end' | 'right-start' | 'right' | 'right-end' | 'bottom-start' | 'bottom' | 'bottom-end';
26
28
  sure?: Function;
27
29
  clear?: Function;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ew-color-picker/core",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "core for ew-color-picker",
5
5
  "main": "dist/core.min.js",
6
6
  "module": "dist/core.esm.js",
@@ -27,7 +27,7 @@
27
27
  "directory": "packages/core"
28
28
  },
29
29
  "dependencies": {
30
- "@ew-color-picker/utils": "^2.0.0"
30
+ "@ew-color-picker/utils": "^2.0.2"
31
31
  },
32
32
  "devDependencies": {
33
33
  "rollup": "^3.29.5",