@ew-color-picker/core 2.0.3 → 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/core.esm.js +16 -16
- package/dist/core.min.js +1 -1
- package/dist/packages/core/src/mergeOptions.d.ts +1 -0
- package/package.json +2 -2
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, DEFAULT_PREFIX, ApplyOrder, isUndefined, isNull, warn, isHTMLElement, isString, isObject, tryErrorHandler,
|
|
6
|
+
import { extend, checkContainer, DEFAULT_PREFIX, ApplyOrder, isUndefined, isNull, warn, isHTMLElement, isString, isObject, tryErrorHandler, colorRgbaToHex, colorToRgba, 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
|
+
boundary: null,
|
|
91
92
|
prefix: DEFAULT_PREFIX,
|
|
92
93
|
sure: function () { },
|
|
93
94
|
clear: function () { },
|
|
@@ -144,6 +145,8 @@ var getMountOrderMap = function () {
|
|
|
144
145
|
return mountOrderMap;
|
|
145
146
|
};
|
|
146
147
|
// 应用顺序映射
|
|
148
|
+
// 未声明 applyOrder 的插件按 0 处理,会先于所有 ApplyOrder.Post 插件执行,
|
|
149
|
+
// 同档位再按插件注册/挂载顺序排序。
|
|
147
150
|
var APPLY_ORDER_MAP = (_a = {},
|
|
148
151
|
_a[ApplyOrder.Pre] = -1,
|
|
149
152
|
_a[ApplyOrder.Post] = 1,
|
|
@@ -182,7 +185,9 @@ var ewColorPicker = /** @class */ (function (_super) {
|
|
|
182
185
|
return;
|
|
183
186
|
// 如果点击的是颜色盒子,不关闭(避免与盒子切换逻辑冲突)
|
|
184
187
|
var prefix = _this.options.prefix || DEFAULT_PREFIX;
|
|
185
|
-
var colorBox = rootElement
|
|
188
|
+
var colorBox = rootElement
|
|
189
|
+
? $(".".concat(prefix, "color-picker-box"), rootElement)
|
|
190
|
+
: null;
|
|
186
191
|
if (colorBox && colorBox.contains(target))
|
|
187
192
|
return;
|
|
188
193
|
// 点击面板和盒子之外的区域,关闭面板
|
|
@@ -268,22 +273,14 @@ var ewColorPicker = /** @class */ (function (_super) {
|
|
|
268
273
|
});
|
|
269
274
|
};
|
|
270
275
|
ewColorPicker.prototype.initCoreProperties = function () {
|
|
271
|
-
var _a;
|
|
272
|
-
var _b = this.options, defaultColor = _b.defaultColor, alphaDirection = _b.alphaDirection, hueDirection = _b.hueDirection;
|
|
276
|
+
var _a = this.options, defaultColor = _a.defaultColor, alphaDirection = _a.alphaDirection, hueDirection = _a.hueDirection;
|
|
273
277
|
if (defaultColor) {
|
|
274
278
|
var defaultColorValue = defaultColor;
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
// 如果 defaultColor 是 rgba 格式,转换为 hex 格式
|
|
284
|
-
if (defaultColor.startsWith("rgba")) {
|
|
285
|
-
defaultColorValue = colorRgbaToHex(defaultColor);
|
|
286
|
-
}
|
|
279
|
+
// 注意:此时实例插件尚未创建,需通过静态插件注册表判断 alpha 插件是否已注册
|
|
280
|
+
var hasAlphaPlugin = ewColorPicker.pluginsMap["ewColorPickerAlpha"];
|
|
281
|
+
// 未启用 alpha 插件时,rgba 默认值降级为 hex,避免保留无效的透明度信息
|
|
282
|
+
if (!hasAlphaPlugin && defaultColor.startsWith("rgba")) {
|
|
283
|
+
defaultColorValue = colorRgbaToHex(defaultColor);
|
|
287
284
|
}
|
|
288
285
|
this.currentColor = defaultColorValue;
|
|
289
286
|
var rgbaColor = colorToRgba(defaultColorValue);
|
|
@@ -414,6 +411,9 @@ var ewColorPicker = /** @class */ (function (_super) {
|
|
|
414
411
|
}
|
|
415
412
|
_this.syncAllPlugins(_this.currentColor);
|
|
416
413
|
setTimeout(function () {
|
|
414
|
+
// 实例可能在这个回调执行前已被销毁
|
|
415
|
+
if (_this.isDestroyed)
|
|
416
|
+
return;
|
|
417
417
|
var panelPlugin = _this.plugins.ewColorPickerPanel;
|
|
418
418
|
if (panelPlugin && isFunction(panelPlugin.handleAutoPosition)) {
|
|
419
419
|
panelPlugin.handleAutoPosition.call(panelPlugin);
|
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,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})});
|
|
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",boundary:null,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=this.options,t=e.defaultColor,n=e.alphaDirection,e=e.hueDirection;t?(o=t,!P.pluginsMap.ewColorPickerAlpha&&t.startsWith("rgba")&&(o=u.colorRgbaToHex(t)),this.currentColor=o,t=(t=u.colorToRgba(o))||"rgba(255, 0, 0, 1)",o=u.colorRgbaToHsva(t),isNaN(o.h)?this.hsvaColor={h:0,s:100,v:100,a:1}:this.hsvaColor=o):(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"===e,this.isAlphaHorizontal="horizontal"===n,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.isDestroyed||((o=s.plugins.ewColorPickerPanel)&&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||(t=n.mountPoints.get("panelContainer"),e=n.mountPoints.get("root"),o=o.target,t&&t.contains(o))||(t=n.options.prefix||u.DEFAULT_PREFIX,(t=e?u.$(".".concat(t,"color-picker-box"),e):null)&&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})});
|
|
@@ -23,6 +23,7 @@ export interface ewColorPickerOptions {
|
|
|
23
23
|
pickerAnimationTime?: number;
|
|
24
24
|
autoPanelPosition?: boolean;
|
|
25
25
|
appendTo?: string | HTMLElement;
|
|
26
|
+
boundary?: string | HTMLElement | null;
|
|
26
27
|
prefix?: string;
|
|
27
28
|
panelPlacement?: 'top-start' | 'top' | 'top-end' | 'left-start' | 'left' | 'left-end' | 'right-start' | 'right' | 'right-end' | 'bottom-start' | 'bottom' | 'bottom-end';
|
|
28
29
|
sure?: Function;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ew-color-picker/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "core for ew-color-picker",
|
|
5
5
|
"main": "dist/core.min.js",
|
|
6
6
|
"module": "dist/core.esm.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"directory": "packages/core"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@ew-color-picker/utils": "^2.0.
|
|
37
|
+
"@ew-color-picker/utils": "^2.0.5"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"rollup": "^3.29.5",
|