@ew-color-picker/tooltip 2.0.18 → 2.0.20
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.
|
@@ -109,7 +109,9 @@ export default class Tooltip {
|
|
|
109
109
|
private handleBlur;
|
|
110
110
|
private handleTriggerKeydown;
|
|
111
111
|
private handleDocumentKeydown;
|
|
112
|
-
private
|
|
112
|
+
private clickOutsideUnbind;
|
|
113
|
+
private bindClickOutside;
|
|
114
|
+
private unbindClickOutside;
|
|
113
115
|
private bindGlobalEvents;
|
|
114
116
|
private unbindGlobalEvents;
|
|
115
117
|
private setAriaDescribedBy;
|
package/dist/tooltip.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 { isNull, isUndefined, isString, $, isHTMLElement, isFunction, getRect, addClass, toStyleStr, create, setAttr, insertNode, removeElement, getElementSize, parsePlacement, clamp, isPlacement, on, applyExtraAttrs, off, getAttr, removeClass, extend, isBoolean, isArray, DEFAULT_PREFIX } from '@ew-color-picker/utils';
|
|
6
|
+
import { isNull, isUndefined, isString, $, isHTMLElement, isFunction, getRect, addClass, toStyleStr, create, setAttr, insertNode, removeElement, getElementSize, parsePlacement, clamp, isPlacement, on, applyExtraAttrs, off, onClickOutside, getAttr, removeClass, extend, isBoolean, isArray, DEFAULT_PREFIX } from '@ew-color-picker/utils';
|
|
7
7
|
export { isTextTruncated } from '@ew-color-picker/utils';
|
|
8
8
|
|
|
9
9
|
/******************************************************************************
|
|
@@ -110,17 +110,8 @@ var Tooltip = /** @class */ (function () {
|
|
|
110
110
|
_this.doHide(event);
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (!target)
|
|
116
|
-
return;
|
|
117
|
-
if (_this.node && _this.node.contains(target))
|
|
118
|
-
return;
|
|
119
|
-
var anchor = _this.getAnchorElement();
|
|
120
|
-
if (anchor && anchor.contains(target))
|
|
121
|
-
return;
|
|
122
|
-
_this.hide();
|
|
123
|
-
};
|
|
113
|
+
// 外部点击关闭:浮层与触发元素都算内部,位置不可靠时按坐标兜底
|
|
114
|
+
this.clickOutsideUnbind = null;
|
|
124
115
|
this.options = extend({
|
|
125
116
|
prefix: DEFAULT_PREFIX,
|
|
126
117
|
rawContent: false,
|
|
@@ -602,6 +593,23 @@ var Tooltip = /** @class */ (function () {
|
|
|
602
593
|
this.requestOpen(event);
|
|
603
594
|
}
|
|
604
595
|
};
|
|
596
|
+
Tooltip.prototype.bindClickOutside = function () {
|
|
597
|
+
var _this = this;
|
|
598
|
+
if (this.clickOutsideUnbind)
|
|
599
|
+
return;
|
|
600
|
+
this.clickOutsideUnbind = onClickOutside({
|
|
601
|
+
targets: function () { return [_this.node, _this.getAnchorElement()]; },
|
|
602
|
+
handler: function () { return _this.hide(); },
|
|
603
|
+
eventName: "click",
|
|
604
|
+
capture: true,
|
|
605
|
+
rectFallback: true,
|
|
606
|
+
});
|
|
607
|
+
};
|
|
608
|
+
Tooltip.prototype.unbindClickOutside = function () {
|
|
609
|
+
var _a;
|
|
610
|
+
(_a = this.clickOutsideUnbind) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
611
|
+
this.clickOutsideUnbind = null;
|
|
612
|
+
};
|
|
605
613
|
Tooltip.prototype.bindGlobalEvents = function () {
|
|
606
614
|
if (this.globalBound)
|
|
607
615
|
return;
|
|
@@ -609,7 +617,7 @@ var Tooltip = /** @class */ (function () {
|
|
|
609
617
|
on(window, "resize", this.scheduleUpdate);
|
|
610
618
|
on(document, "keydown", this.handleDocumentKeydown);
|
|
611
619
|
if (this.triggerList.indexOf("click") > -1) {
|
|
612
|
-
|
|
620
|
+
this.bindClickOutside();
|
|
613
621
|
}
|
|
614
622
|
this.globalBound = true;
|
|
615
623
|
};
|
|
@@ -619,9 +627,7 @@ var Tooltip = /** @class */ (function () {
|
|
|
619
627
|
off(window, "scroll", this.scheduleUpdate, { capture: true });
|
|
620
628
|
off(window, "resize", this.scheduleUpdate);
|
|
621
629
|
off(document, "keydown", this.handleDocumentKeydown);
|
|
622
|
-
|
|
623
|
-
off(document, "click", this.handleDocumentClick, { capture: true });
|
|
624
|
-
}
|
|
630
|
+
this.unbindClickOutside();
|
|
625
631
|
this.globalBound = false;
|
|
626
632
|
if (this.positionFrame !== null) {
|
|
627
633
|
if (typeof cancelAnimationFrame === "function") {
|
package/dist/tooltip.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
((t,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((t="undefined"!=typeof globalThis?globalThis:t||self).Tooltip={},t.Utils)})(this,function(t,d){var e=function(){return(e=Object.assign||function(t){for(var e,i=1,o=arguments.length;i<o;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)},i=["hover","click","focus","contextmenu"],h={top:"bottom",bottom:"top",left:"right",right:"left"},o=0;function n(t){return-1<i.indexOf(t)}function r(t){var e;return d.isArray(t)?(e=t.filter(n)).length?e:["hover"]:n(t)?[t]:["hover"]}Object.defineProperty(p.prototype,"prefix",{get:function(){return this.options.prefix},enumerable:!1,configurable:!0}),Object.defineProperty(p.prototype,"strategy",{get:function(){return"absolute"===this.options.popperOptions.strategy?"absolute":"fixed"},enumerable:!1,configurable:!0}),Object.defineProperty(p.prototype,"triggerList",{get:function(){return this.options.trigger},enumerable:!1,configurable:!0}),p.prototype.hasContent=function(t){return void 0===t&&(t=this.currentContent),!d.isNull(t)&&!d.isUndefined(t)&&(!d.isString(t)||0<t.trim().length)},p.prototype.resolveElement=function(t){return t?d.isString(t)?d.$(t):t:null},p.prototype.getAnchorElement=function(){var t;return this.options.virtualTriggering?(t=this.options.virtualRef,d.isHTMLElement(t)?t:null):this.imperativeAnchor||this.resolveElement(this.options.target)},p.prototype.getAnchorRect=function(){var t;return this.options.virtualTriggering?(t=this.options.virtualRef)&&d.isFunction(t.getBoundingClientRect)?t.getBoundingClientRect():null:(t=this.getAnchorElement())?d.getRect(t):null},p.prototype.getParent=function(){var t;return!1===this.options.teleported?(null==(t=this.getAnchorElement())?void 0:t.parentElement)||document.body:(t=null!=(t=this.options.appendTo)?t:this.options.container,d.isString(t)?d.$(t)||document.body:t||document.body)},p.prototype.applyCustomClasses=function(t){var e=[this.options.popperClass,this.options.className].filter(Boolean).join(" ");e&&d.addClass(t,e),this.options.transition&&d.addClass(t,this.options.transition)},p.prototype.applyPopperStyle=function(t){var e=this.options.popperStyle;e&&(t.style.cssText+=d.isString(e)?e:d.toStyleStr(e))},p.prototype.ensureNode=function(){var t,e;return this.node?(this.attachNode(),this.node):(t=this.prefix,(e=d.create("div")).id="".concat(t,"tooltip-").concat(++o),d.addClass(e,"".concat(t,"tooltip")),d.addClass(e,"".concat(t,"tooltip--").concat(this.options.effect)),this.options.enterable&&d.addClass(e,"".concat(t,"tooltip--enterable")),d.setAttr(e,{role:"tooltip"}),this.options.ariaLabel&&d.setAttr(e,{"aria-label":this.options.ariaLabel}),this.applyCustomClasses(e),e.style.position=this.strategy,this.contentNode=d.create("div"),d.addClass(this.contentNode,"".concat(t,"tooltip__content")),d.insertNode(e,this.contentNode),this.arrowNode=d.create("div"),d.addClass(this.arrowNode,"".concat(t,"tooltip__arrow")),this.options.showArrow||(this.arrowNode.style.display="none"),d.insertNode(e,this.arrowNode),this.applyPopperStyle(e),this.node=e,this.attachNode(),this.bindPopperEvents(),e)},p.prototype.attachNode=function(){var t;this.node&&(t=this.getParent())&&this.node.parentNode!==t&&t.appendChild(this.node)},p.prototype.applyContent=function(){var t,e=this.contentNode;e&&(t=this.currentContent,e.textContent="",d.isNull(t)||d.isUndefined(t)||(d.isString(t)?this.options.html||this.options.rawContent?e.innerHTML=t:e.textContent=t:d.isHTMLElement(t)?e.appendChild(t):e.textContent=String(t)))},p.prototype.destroyNode=function(){this.unbindPopperEvents(),this.node&&(d.removeElement(this.node),this.node=null),this.contentNode=null,this.arrowNode=null},p.prototype.getNodeSize=function(){var t;return this.node?{width:(t=d.getElementSize(this.node)).offsetWidth||0,height:t.offsetHeight||0}:{width:0,height:0}},p.prototype.computeCoords=function(t,e,i){function o(){return"start"===r?e.left:"end"===r?e.right-i.width:e.left+(e.width-i.width)/2}function n(){return"start"===r?e.top:"end"===r?e.bottom-i.height:e.top+(e.height-i.height)/2}var t=d.parsePlacement(t),s=t.side,r=t.align,p=this.options.offset,h=0,a=0;switch(s){case"top":a=e.top-p-i.height,h=o();break;case"bottom":a=e.bottom+p,h=o();break;case"left":h=e.left-p-i.width,a=n();break;case"right":h=e.right+p,a=n()}var t=window.innerWidth,l=window.innerHeight;return"top"===s||"bottom"===s?h=d.clamp(h,5,Math.max(5,t-i.width-5)):a=d.clamp(a,5,Math.max(5,l-i.height-5)),"absolute"===this.strategy&&(h+=window.scrollX||window.pageXOffset||0,a+=window.scrollY||window.pageYOffset||0),{left:h,top:a}},p.prototype.fitsViewport=function(t,e,i){var t=d.parsePlacement(t).side,o=this.options.offset,n=window.innerWidth,s=window.innerHeight;switch(t){case"top":return 5<=e.top-o-i.height;case"bottom":return e.bottom+o+i.height<=s-5;case"left":return 5<=e.left-o-i.width;case"right":return e.right+o+i.width<=n-5}},p.prototype.resolvePlacement=function(t,e){var i=this.options.placement;if(!this.fitsViewport(i,t,e))for(var o=d.parsePlacement(i),n=o.side,o=o.align,n=h[n],n="center"===o?n:"".concat(n,"-").concat(o),s=0,r=this.options.fallbackPlacements.length?this.options.fallbackPlacements:[n];s<r.length;s++){var p=r[s];if(d.isPlacement(p)&&this.fitsViewport(p,t,e))return p}return i},p.prototype.updateArrow=function(t,e,i,o){var n,s,r,p=this.arrowNode;p&&(this.options.showArrow?(p.style.display="",p.style.left="",p.style.right="",p.style.top="",p.style.bottom="",n=d.parsePlacement(t).side,s=this.options.arrowOffset,"top"===n||"bottom"===n?(r=e.left+e.width/2-i.left,o.width>2*s&&(r=d.clamp(r,s,o.width-s)),p.style.left="".concat(r-4,"px"),"top"===n?p.style.bottom="".concat(-4,"px"):p.style.top="".concat(-4,"px")):(r=e.top+e.height/2-i.top,o.height>2*s&&(r=d.clamp(r,s,o.height-s)),p.style.top="".concat(r-4,"px"),"left"===n?p.style.right="".concat(-4,"px"):p.style.left="".concat(-4,"px")),d.setAttr(p,{"data-placement":t})):p.style.display="none")},p.prototype.updatePosition=function(){var t,e,i,o,n=this.node;n&&(t=this.getAnchorRect())&&(e=this.getNodeSize(),i=this.resolvePlacement(t,e),o=this.computeCoords(i,t,e),n.style.left="".concat(Math.round(o.left),"px"),n.style.top="".concat(Math.round(o.top),"px"),d.setAttr(n,{"data-placement":i,"data-popper-placement":i}),this.updateArrow(i,t,o,e))},p.prototype.addTriggerListener=function(t,e,i){d.on(t,e,i),this.triggerListeners.push({el:t,type:e,handler:i})},p.prototype.applyTargetAttrs=function(){var e=this,t=this.resolveElement(this.options.target);t&&(this.targetAttrEl&&this.targetAttrEl!==t&&(Object.keys(this.appliedTargetAttrs).forEach(function(t){e.targetAttrEl.removeAttribute(t)}),this.appliedTargetAttrs={}),this.targetAttrEl=t,this.appliedTargetAttrs=d.applyExtraAttrs(t,this.options.attrs||{},this.appliedTargetAttrs))},p.prototype.setAttrs=function(t){this.options.attrs=e({},t=void 0===t?{}:t),this.applyTargetAttrs()},p.prototype.bindTriggerEvents=function(){var t,e,i,o,n,s=this;this.unbindTriggerEvents(),this.options.virtualTriggering||(t=this.resolveElement(this.options.target))&&(this.applyTargetAttrs(),e=-1<(n=this.triggerList).indexOf("hover"),i=-1<n.indexOf("click"),o=-1<n.indexOf("focus"),n=-1<n.indexOf("contextmenu"),e&&(this.addTriggerListener(t,"mouseenter",function(){return s.requestOpen()}),this.addTriggerListener(t,"mouseleave",function(t){return s.requestHide(t)}),this.addTriggerListener(t,"focus",function(){return s.requestOpen()}),this.addTriggerListener(t,"blur",function(t){return s.handleBlur(t)})),o&&!e&&(this.addTriggerListener(t,"focus",function(){return s.requestOpen()}),this.addTriggerListener(t,"blur",function(t){return s.handleBlur(t)})),i&&(this.addTriggerListener(t,"click",function(){s.isOpen?s.hide():s.requestOpen()}),this.addTriggerListener(t,"keydown",function(t){return s.handleTriggerKeydown(t)})),n)&&this.addTriggerListener(t,"contextmenu",function(t){t.preventDefault(),s.requestOpen(t)})},p.prototype.unbindTriggerEvents=function(){this.triggerListeners.forEach(function(t){var e=t.el;d.off(e,t.type,t.handler)}),this.triggerListeners=[]},p.prototype.bindPopperEvents=function(){var t,e,i=this;this.node&&!this.popperListeners.length&&(e=function(t){return i.requestHide(t)},d.on(this.node,"mouseenter",t=function(){return i.clearHideTimer()}),d.on(this.node,"mouseleave",e),this.popperListeners=[{type:"mouseenter",handler:t},{type:"mouseleave",handler:e}])},p.prototype.unbindPopperEvents=function(){var i=this;this.node&&this.popperListeners.forEach(function(t){var e=t.type;d.off(i.node,e,t.handler)}),this.popperListeners=[]},p.prototype.handleBlur=function(t){var e=t.relatedTarget;e&&this.node&&this.node.contains(e)&&this.options.enterable||this.requestHide(t)},p.prototype.handleTriggerKeydown=function(t){var e=this.options.triggerKeys;!(-1<e.indexOf(t.key)||-1<e.indexOf(t.code))||this.isOpen||this.options.disabled||(t.preventDefault(),this.requestOpen(t))},p.prototype.bindGlobalEvents=function(){this.globalBound||(d.on(window,"scroll",this.scheduleUpdate,{capture:!0}),d.on(window,"resize",this.scheduleUpdate),d.on(document,"keydown",this.handleDocumentKeydown),-1<this.triggerList.indexOf("click")&&d.on(document,"click",this.handleDocumentClick,{capture:!0}),this.globalBound=!0)},p.prototype.unbindGlobalEvents=function(){this.globalBound&&(d.off(window,"scroll",this.scheduleUpdate,{capture:!0}),d.off(window,"resize",this.scheduleUpdate),d.off(document,"keydown",this.handleDocumentKeydown),-1<this.triggerList.indexOf("click")&&d.off(document,"click",this.handleDocumentClick,{capture:!0}),this.globalBound=!1,null!==this.positionFrame)&&("function"==typeof cancelAnimationFrame&&cancelAnimationFrame(this.positionFrame),this.positionFrame=null)},p.prototype.setAriaDescribedBy=function(t){var e=this.getAnchorElement();e&&this.node&&(t?(this.prevAriaDescribedBy=d.getAttr(e,"aria-describedby"),d.setAttr(e,{"aria-describedby":this.node.id})):d.getAttr(e,"aria-describedby")===this.node.id&&(this.prevAriaDescribedBy?d.setAttr(e,{"aria-describedby":this.prevAriaDescribedBy}):e.removeAttribute("aria-describedby")))},p.prototype.emit=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];var o=this.listeners[t],o=(o&&o.forEach(function(t){return t.apply(void 0,e)}),"on".concat(t.charAt(0).toUpperCase()).concat(t.slice(1))),t=this.options[o];d.isFunction(t)&&t.apply(void 0,e)},p.prototype.clearShowTimer=function(){this.showTimer&&(clearTimeout(this.showTimer),this.showTimer=null)},p.prototype.clearHideTimer=function(){this.hideTimer&&(clearTimeout(this.hideTimer),this.hideTimer=null)},p.prototype.clearAutoCloseTimer=function(){this.autoCloseTimer&&(clearTimeout(this.autoCloseTimer),this.autoCloseTimer=null)},p.prototype.requestOpen=function(t){var e,i=this;this.options.disabled||(this.clearHideTimer(),this.isOpen)||(this.controlled?this.emit("visibleChange",!0):0<(e=this.options.showAfter)?(this.clearShowTimer(),this.showTimer=setTimeout(function(){return i.doOpen(t)},e)):this.doOpen(t))},p.prototype.requestHide=function(t){var e,i=this;this.clearShowTimer(),this.isOpen&&(this.controlled?this.emit("visibleChange",!1):0<(e=this.options.hideAfter)?(this.clearHideTimer(),this.hideTimer=setTimeout(function(){return i.doHide(t)},e)):this.doHide(t))},p.prototype.doOpen=function(t){var e,i=this;!this.options.disabled&&this.hasContent()&&(this.triggerListeners.length||this.options.virtualTriggering||this.bindTriggerEvents(),this.isOpen?(this.applyContent(),this.updatePosition()):(this.clearTimers(),this.emit("beforeShow",t),e=this.ensureNode(),this.applyContent(),d.addClass(e,"".concat(this.prefix,"tooltip--visible")),this.isOpen=!0,this.updatePosition(),this.bindGlobalEvents(),this.setAriaDescribedBy(!0),this.emit("show",t),this.emit("visibleChange",!0),0<this.options.autoClose&&(this.autoCloseTimer=setTimeout(function(){i.doHide()},this.options.autoClose))))},p.prototype.doHide=function(t){this.isOpen&&(this.emit("beforeHide",t),this.isOpen=!1,this.node&&d.removeClass(this.node,"".concat(this.prefix,"tooltip--visible")),this.setAriaDescribedBy(!1),this.unbindGlobalEvents(),this.clearTimers(),this.emit("hide",t),this.emit("visibleChange",!1),this.options.persistent||this.destroyNode(),this.options.focusOnTarget)&&null!=(t=this.getAnchorElement())&&t.focus()},p.prototype.clearTimers=function(){this.clearShowTimer(),this.clearHideTimer(),this.clearAutoCloseTimer()},p.prototype.show=function(t,e){e&&(this.imperativeAnchor=e),void 0!==t&&(this.currentContent=t),this.hasContent()?this.options.disabled||(this.controlled?this.emit("visibleChange",!0):this.doOpen()):this.hide()},p.prototype.hide=function(t){this.controlled?this.emit("visibleChange",!1):this.doHide(t)},p.prototype.onOpen=function(){this.requestOpen()},p.prototype.onClose=function(){this.hide()},p.prototype.isVisible=function(){return this.isOpen},p.prototype.getElement=function(){return this.node},p.prototype.getContentElement=function(){return this.contentNode},p.prototype.getTrigger=function(){return this.resolveElement(this.options.target)},p.prototype.isFocusInsideContent=function(){return Boolean(this.node&&this.node.contains(document.activeElement))},p.prototype.updatePopper=function(){this.updatePosition()},p.prototype.setContent=function(t){this.currentContent=t,this.isOpen&&(this.applyContent(),this.updatePosition())},p.prototype.setOptions=function(t){var e=this.options.target,i=this.options.trigger.join(","),o=this.options.appendTo,n=this.options.container,s=this.options.virtualTriggering;this.options=d.extend(this.options,t),void 0!==t.trigger&&(this.options.trigger=r(t.trigger)),t.triggerKeys&&(this.options.triggerKeys=t.triggerKeys),t.popperOptions&&(this.options.popperOptions=t.popperOptions),void 0!==t.content&&(this.currentContent=t.content),Object.prototype.hasOwnProperty.call(t,"visible")&&(this.controlled=d.isBoolean(t.visible)),void 0!==t.attrs&&this.applyTargetAttrs(),void 0===t.target&&void 0===t.trigger&&void 0===t.virtualTriggering&&e===this.options.target&&i===this.options.trigger.join(",")&&s===this.options.virtualTriggering||this.bindTriggerEvents(),!this.node||void 0===t.appendTo&&void 0===t.container&&void 0===t.teleported&&o===this.options.appendTo&&n===this.options.container||this.attachNode(),this.node&&(e=this.prefix,this.node.style.position=this.strategy,d.removeClass(this.node,"".concat(e,"tooltip--dark")),d.removeClass(this.node,"".concat(e,"tooltip--light")),d.addClass(this.node,"".concat(e,"tooltip--").concat(this.options.effect)),this.options.enterable?d.addClass(this.node,"".concat(e,"tooltip--enterable")):d.removeClass(this.node,"".concat(e,"tooltip--enterable")),this.arrowNode&&(this.arrowNode.style.display=this.options.showArrow?"":"none"),this.options.ariaLabel&&d.setAttr(this.node,{"aria-label":this.options.ariaLabel}),this.options.popperClass&&d.addClass(this.node,this.options.popperClass),this.options.popperStyle&&this.applyPopperStyle(this.node),this.isOpen)&&(this.applyContent(),this.updatePosition()),this.options.disabled?this.doHide():this.controlled&&(this.options.visible?this.doOpen():this.doHide())},p.prototype.on=function(t,e){return this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(e),this},p.prototype.off=function(t,e){var i=this.listeners[t];return i&&(this.listeners[t]=e?i.filter(function(t){return t!==e}):[]),this},p.prototype.destroy=function(){this.clearTimers(),this.unbindTriggerEvents(),this.unbindGlobalEvents(),this.unbindPopperEvents(),this.setAriaDescribedBy(!1),this.destroyNode(),this.currentContent=void 0,this.imperativeAnchor=null,this.isOpen=!1,this.listeners={},this.controlled=!1};var s=p;function p(t){void 0===t&&(t={});var i=this;this.node=null,this.contentNode=null,this.arrowNode=null,this.isOpen=!1,this.controlled=!1,this.currentContent=void 0,this.imperativeAnchor=null,this.prevAriaDescribedBy=null,this.showTimer=null,this.hideTimer=null,this.autoCloseTimer=null,this.positionFrame=null,this.globalBound=!1,this.triggerListeners=[],this.targetAttrEl=null,this.appliedTargetAttrs={},this.popperListeners=[],this.listeners={},this.scheduleUpdate=function(){var t;null===i.positionFrame&&(t="function"==typeof requestAnimationFrame?requestAnimationFrame:function(t){return setTimeout(function(){return t(Date.now())},16)},i.positionFrame=t(function(){i.positionFrame=null,i.updatePosition()}))},this.handleDocumentKeydown=function(t){"Escape"===t.key&&i.isOpen&&i.doHide(t)},this.handleDocumentClick=function(t){var e,t=t.target;!t||i.node&&i.node.contains(t)||(e=i.getAnchorElement())&&e.contains(t)||i.hide()},this.options=d.extend({prefix:d.DEFAULT_PREFIX,rawContent:!1,effect:"dark",placement:"bottom",fallbackPlacements:[],disabled:!1,offset:12,arrowOffset:5,showArrow:!0,showAfter:0,hideAfter:200,autoClose:0,popperClass:"",popperStyle:"",teleported:!0,enterable:!0,triggerKeys:["Enter","Space"],persistent:!0,transition:"",ariaLabel:"",focusOnTarget:!1,popperOptions:{},className:""},t),this.options.trigger=r(t.trigger),this.options.popperOptions=t.popperOptions||{},this.options.triggerKeys=t.triggerKeys||["Enter","Space"],this.controlled=Object.prototype.hasOwnProperty.call(t,"visible")&&d.isBoolean(t.visible),this.currentContent=t.content,this.bindTriggerEvents(),this.controlled&&this.options.visible&&this.doOpen()}Object.defineProperty(t,"isTextTruncated",{enumerable:!0,get:function(){return d.isTextTruncated}}),t.Tooltip=s,t.default=s,Object.defineProperty(t,"__esModule",{value:!0})});
|
|
1
|
+
((t,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((t="undefined"!=typeof globalThis?globalThis:t||self).Tooltip={},t.Utils)})(this,function(t,d){var e=function(){return(e=Object.assign||function(t){for(var e,i=1,o=arguments.length;i<o;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)},i=["hover","click","focus","contextmenu"],h={top:"bottom",bottom:"top",left:"right",right:"left"},o=0;function n(t){return-1<i.indexOf(t)}function r(t){var e;return d.isArray(t)?(e=t.filter(n)).length?e:["hover"]:n(t)?[t]:["hover"]}Object.defineProperty(p.prototype,"prefix",{get:function(){return this.options.prefix},enumerable:!1,configurable:!0}),Object.defineProperty(p.prototype,"strategy",{get:function(){return"absolute"===this.options.popperOptions.strategy?"absolute":"fixed"},enumerable:!1,configurable:!0}),Object.defineProperty(p.prototype,"triggerList",{get:function(){return this.options.trigger},enumerable:!1,configurable:!0}),p.prototype.hasContent=function(t){return void 0===t&&(t=this.currentContent),!d.isNull(t)&&!d.isUndefined(t)&&(!d.isString(t)||0<t.trim().length)},p.prototype.resolveElement=function(t){return t?d.isString(t)?d.$(t):t:null},p.prototype.getAnchorElement=function(){var t;return this.options.virtualTriggering?(t=this.options.virtualRef,d.isHTMLElement(t)?t:null):this.imperativeAnchor||this.resolveElement(this.options.target)},p.prototype.getAnchorRect=function(){var t;return this.options.virtualTriggering?(t=this.options.virtualRef)&&d.isFunction(t.getBoundingClientRect)?t.getBoundingClientRect():null:(t=this.getAnchorElement())?d.getRect(t):null},p.prototype.getParent=function(){var t;return!1===this.options.teleported?(null==(t=this.getAnchorElement())?void 0:t.parentElement)||document.body:(t=null!=(t=this.options.appendTo)?t:this.options.container,d.isString(t)?d.$(t)||document.body:t||document.body)},p.prototype.applyCustomClasses=function(t){var e=[this.options.popperClass,this.options.className].filter(Boolean).join(" ");e&&d.addClass(t,e),this.options.transition&&d.addClass(t,this.options.transition)},p.prototype.applyPopperStyle=function(t){var e=this.options.popperStyle;e&&(t.style.cssText+=d.isString(e)?e:d.toStyleStr(e))},p.prototype.ensureNode=function(){var t,e;return this.node?(this.attachNode(),this.node):(t=this.prefix,(e=d.create("div")).id="".concat(t,"tooltip-").concat(++o),d.addClass(e,"".concat(t,"tooltip")),d.addClass(e,"".concat(t,"tooltip--").concat(this.options.effect)),this.options.enterable&&d.addClass(e,"".concat(t,"tooltip--enterable")),d.setAttr(e,{role:"tooltip"}),this.options.ariaLabel&&d.setAttr(e,{"aria-label":this.options.ariaLabel}),this.applyCustomClasses(e),e.style.position=this.strategy,this.contentNode=d.create("div"),d.addClass(this.contentNode,"".concat(t,"tooltip__content")),d.insertNode(e,this.contentNode),this.arrowNode=d.create("div"),d.addClass(this.arrowNode,"".concat(t,"tooltip__arrow")),this.options.showArrow||(this.arrowNode.style.display="none"),d.insertNode(e,this.arrowNode),this.applyPopperStyle(e),this.node=e,this.attachNode(),this.bindPopperEvents(),e)},p.prototype.attachNode=function(){var t;this.node&&(t=this.getParent())&&this.node.parentNode!==t&&t.appendChild(this.node)},p.prototype.applyContent=function(){var t,e=this.contentNode;e&&(t=this.currentContent,e.textContent="",d.isNull(t)||d.isUndefined(t)||(d.isString(t)?this.options.html||this.options.rawContent?e.innerHTML=t:e.textContent=t:d.isHTMLElement(t)?e.appendChild(t):e.textContent=String(t)))},p.prototype.destroyNode=function(){this.unbindPopperEvents(),this.node&&(d.removeElement(this.node),this.node=null),this.contentNode=null,this.arrowNode=null},p.prototype.getNodeSize=function(){var t;return this.node?{width:(t=d.getElementSize(this.node)).offsetWidth||0,height:t.offsetHeight||0}:{width:0,height:0}},p.prototype.computeCoords=function(t,e,i){function o(){return"start"===r?e.left:"end"===r?e.right-i.width:e.left+(e.width-i.width)/2}function n(){return"start"===r?e.top:"end"===r?e.bottom-i.height:e.top+(e.height-i.height)/2}var t=d.parsePlacement(t),s=t.side,r=t.align,p=this.options.offset,h=0,a=0;switch(s){case"top":a=e.top-p-i.height,h=o();break;case"bottom":a=e.bottom+p,h=o();break;case"left":h=e.left-p-i.width,a=n();break;case"right":h=e.right+p,a=n()}var t=window.innerWidth,l=window.innerHeight;return"top"===s||"bottom"===s?h=d.clamp(h,5,Math.max(5,t-i.width-5)):a=d.clamp(a,5,Math.max(5,l-i.height-5)),"absolute"===this.strategy&&(h+=window.scrollX||window.pageXOffset||0,a+=window.scrollY||window.pageYOffset||0),{left:h,top:a}},p.prototype.fitsViewport=function(t,e,i){var t=d.parsePlacement(t).side,o=this.options.offset,n=window.innerWidth,s=window.innerHeight;switch(t){case"top":return 5<=e.top-o-i.height;case"bottom":return e.bottom+o+i.height<=s-5;case"left":return 5<=e.left-o-i.width;case"right":return e.right+o+i.width<=n-5}},p.prototype.resolvePlacement=function(t,e){var i=this.options.placement;if(!this.fitsViewport(i,t,e))for(var o=d.parsePlacement(i),n=o.side,o=o.align,n=h[n],n="center"===o?n:"".concat(n,"-").concat(o),s=0,r=this.options.fallbackPlacements.length?this.options.fallbackPlacements:[n];s<r.length;s++){var p=r[s];if(d.isPlacement(p)&&this.fitsViewport(p,t,e))return p}return i},p.prototype.updateArrow=function(t,e,i,o){var n,s,r,p=this.arrowNode;p&&(this.options.showArrow?(p.style.display="",p.style.left="",p.style.right="",p.style.top="",p.style.bottom="",n=d.parsePlacement(t).side,s=this.options.arrowOffset,"top"===n||"bottom"===n?(r=e.left+e.width/2-i.left,o.width>2*s&&(r=d.clamp(r,s,o.width-s)),p.style.left="".concat(r-4,"px"),"top"===n?p.style.bottom="".concat(-4,"px"):p.style.top="".concat(-4,"px")):(r=e.top+e.height/2-i.top,o.height>2*s&&(r=d.clamp(r,s,o.height-s)),p.style.top="".concat(r-4,"px"),"left"===n?p.style.right="".concat(-4,"px"):p.style.left="".concat(-4,"px")),d.setAttr(p,{"data-placement":t})):p.style.display="none")},p.prototype.updatePosition=function(){var t,e,i,o,n=this.node;n&&(t=this.getAnchorRect())&&(e=this.getNodeSize(),i=this.resolvePlacement(t,e),o=this.computeCoords(i,t,e),n.style.left="".concat(Math.round(o.left),"px"),n.style.top="".concat(Math.round(o.top),"px"),d.setAttr(n,{"data-placement":i,"data-popper-placement":i}),this.updateArrow(i,t,o,e))},p.prototype.addTriggerListener=function(t,e,i){d.on(t,e,i),this.triggerListeners.push({el:t,type:e,handler:i})},p.prototype.applyTargetAttrs=function(){var e=this,t=this.resolveElement(this.options.target);t&&(this.targetAttrEl&&this.targetAttrEl!==t&&(Object.keys(this.appliedTargetAttrs).forEach(function(t){e.targetAttrEl.removeAttribute(t)}),this.appliedTargetAttrs={}),this.targetAttrEl=t,this.appliedTargetAttrs=d.applyExtraAttrs(t,this.options.attrs||{},this.appliedTargetAttrs))},p.prototype.setAttrs=function(t){this.options.attrs=e({},t=void 0===t?{}:t),this.applyTargetAttrs()},p.prototype.bindTriggerEvents=function(){var t,e,i,o,n,s=this;this.unbindTriggerEvents(),this.options.virtualTriggering||(t=this.resolveElement(this.options.target))&&(this.applyTargetAttrs(),e=-1<(n=this.triggerList).indexOf("hover"),i=-1<n.indexOf("click"),o=-1<n.indexOf("focus"),n=-1<n.indexOf("contextmenu"),e&&(this.addTriggerListener(t,"mouseenter",function(){return s.requestOpen()}),this.addTriggerListener(t,"mouseleave",function(t){return s.requestHide(t)}),this.addTriggerListener(t,"focus",function(){return s.requestOpen()}),this.addTriggerListener(t,"blur",function(t){return s.handleBlur(t)})),o&&!e&&(this.addTriggerListener(t,"focus",function(){return s.requestOpen()}),this.addTriggerListener(t,"blur",function(t){return s.handleBlur(t)})),i&&(this.addTriggerListener(t,"click",function(){s.isOpen?s.hide():s.requestOpen()}),this.addTriggerListener(t,"keydown",function(t){return s.handleTriggerKeydown(t)})),n)&&this.addTriggerListener(t,"contextmenu",function(t){t.preventDefault(),s.requestOpen(t)})},p.prototype.unbindTriggerEvents=function(){this.triggerListeners.forEach(function(t){var e=t.el;d.off(e,t.type,t.handler)}),this.triggerListeners=[]},p.prototype.bindPopperEvents=function(){var t,e,i=this;this.node&&!this.popperListeners.length&&(e=function(t){return i.requestHide(t)},d.on(this.node,"mouseenter",t=function(){return i.clearHideTimer()}),d.on(this.node,"mouseleave",e),this.popperListeners=[{type:"mouseenter",handler:t},{type:"mouseleave",handler:e}])},p.prototype.unbindPopperEvents=function(){var i=this;this.node&&this.popperListeners.forEach(function(t){var e=t.type;d.off(i.node,e,t.handler)}),this.popperListeners=[]},p.prototype.handleBlur=function(t){var e=t.relatedTarget;e&&this.node&&this.node.contains(e)&&this.options.enterable||this.requestHide(t)},p.prototype.handleTriggerKeydown=function(t){var e=this.options.triggerKeys;!(-1<e.indexOf(t.key)||-1<e.indexOf(t.code))||this.isOpen||this.options.disabled||(t.preventDefault(),this.requestOpen(t))},p.prototype.bindClickOutside=function(){var t=this;this.clickOutsideUnbind||(this.clickOutsideUnbind=d.onClickOutside({targets:function(){return[t.node,t.getAnchorElement()]},handler:function(){return t.hide()},eventName:"click",capture:!0,rectFallback:!0}))},p.prototype.unbindClickOutside=function(){var t;null!=(t=this.clickOutsideUnbind)&&t.call(this),this.clickOutsideUnbind=null},p.prototype.bindGlobalEvents=function(){this.globalBound||(d.on(window,"scroll",this.scheduleUpdate,{capture:!0}),d.on(window,"resize",this.scheduleUpdate),d.on(document,"keydown",this.handleDocumentKeydown),-1<this.triggerList.indexOf("click")&&this.bindClickOutside(),this.globalBound=!0)},p.prototype.unbindGlobalEvents=function(){this.globalBound&&(d.off(window,"scroll",this.scheduleUpdate,{capture:!0}),d.off(window,"resize",this.scheduleUpdate),d.off(document,"keydown",this.handleDocumentKeydown),this.unbindClickOutside(),this.globalBound=!1,null!==this.positionFrame)&&("function"==typeof cancelAnimationFrame&&cancelAnimationFrame(this.positionFrame),this.positionFrame=null)},p.prototype.setAriaDescribedBy=function(t){var e=this.getAnchorElement();e&&this.node&&(t?(this.prevAriaDescribedBy=d.getAttr(e,"aria-describedby"),d.setAttr(e,{"aria-describedby":this.node.id})):d.getAttr(e,"aria-describedby")===this.node.id&&(this.prevAriaDescribedBy?d.setAttr(e,{"aria-describedby":this.prevAriaDescribedBy}):e.removeAttribute("aria-describedby")))},p.prototype.emit=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];var o=this.listeners[t],o=(o&&o.forEach(function(t){return t.apply(void 0,e)}),"on".concat(t.charAt(0).toUpperCase()).concat(t.slice(1))),t=this.options[o];d.isFunction(t)&&t.apply(void 0,e)},p.prototype.clearShowTimer=function(){this.showTimer&&(clearTimeout(this.showTimer),this.showTimer=null)},p.prototype.clearHideTimer=function(){this.hideTimer&&(clearTimeout(this.hideTimer),this.hideTimer=null)},p.prototype.clearAutoCloseTimer=function(){this.autoCloseTimer&&(clearTimeout(this.autoCloseTimer),this.autoCloseTimer=null)},p.prototype.requestOpen=function(t){var e,i=this;this.options.disabled||(this.clearHideTimer(),this.isOpen)||(this.controlled?this.emit("visibleChange",!0):0<(e=this.options.showAfter)?(this.clearShowTimer(),this.showTimer=setTimeout(function(){return i.doOpen(t)},e)):this.doOpen(t))},p.prototype.requestHide=function(t){var e,i=this;this.clearShowTimer(),this.isOpen&&(this.controlled?this.emit("visibleChange",!1):0<(e=this.options.hideAfter)?(this.clearHideTimer(),this.hideTimer=setTimeout(function(){return i.doHide(t)},e)):this.doHide(t))},p.prototype.doOpen=function(t){var e,i=this;!this.options.disabled&&this.hasContent()&&(this.triggerListeners.length||this.options.virtualTriggering||this.bindTriggerEvents(),this.isOpen?(this.applyContent(),this.updatePosition()):(this.clearTimers(),this.emit("beforeShow",t),e=this.ensureNode(),this.applyContent(),d.addClass(e,"".concat(this.prefix,"tooltip--visible")),this.isOpen=!0,this.updatePosition(),this.bindGlobalEvents(),this.setAriaDescribedBy(!0),this.emit("show",t),this.emit("visibleChange",!0),0<this.options.autoClose&&(this.autoCloseTimer=setTimeout(function(){i.doHide()},this.options.autoClose))))},p.prototype.doHide=function(t){this.isOpen&&(this.emit("beforeHide",t),this.isOpen=!1,this.node&&d.removeClass(this.node,"".concat(this.prefix,"tooltip--visible")),this.setAriaDescribedBy(!1),this.unbindGlobalEvents(),this.clearTimers(),this.emit("hide",t),this.emit("visibleChange",!1),this.options.persistent||this.destroyNode(),this.options.focusOnTarget)&&null!=(t=this.getAnchorElement())&&t.focus()},p.prototype.clearTimers=function(){this.clearShowTimer(),this.clearHideTimer(),this.clearAutoCloseTimer()},p.prototype.show=function(t,e){e&&(this.imperativeAnchor=e),void 0!==t&&(this.currentContent=t),this.hasContent()?this.options.disabled||(this.controlled?this.emit("visibleChange",!0):this.doOpen()):this.hide()},p.prototype.hide=function(t){this.controlled?this.emit("visibleChange",!1):this.doHide(t)},p.prototype.onOpen=function(){this.requestOpen()},p.prototype.onClose=function(){this.hide()},p.prototype.isVisible=function(){return this.isOpen},p.prototype.getElement=function(){return this.node},p.prototype.getContentElement=function(){return this.contentNode},p.prototype.getTrigger=function(){return this.resolveElement(this.options.target)},p.prototype.isFocusInsideContent=function(){return Boolean(this.node&&this.node.contains(document.activeElement))},p.prototype.updatePopper=function(){this.updatePosition()},p.prototype.setContent=function(t){this.currentContent=t,this.isOpen&&(this.applyContent(),this.updatePosition())},p.prototype.setOptions=function(t){var e=this.options.target,i=this.options.trigger.join(","),o=this.options.appendTo,n=this.options.container,s=this.options.virtualTriggering;this.options=d.extend(this.options,t),void 0!==t.trigger&&(this.options.trigger=r(t.trigger)),t.triggerKeys&&(this.options.triggerKeys=t.triggerKeys),t.popperOptions&&(this.options.popperOptions=t.popperOptions),void 0!==t.content&&(this.currentContent=t.content),Object.prototype.hasOwnProperty.call(t,"visible")&&(this.controlled=d.isBoolean(t.visible)),void 0!==t.attrs&&this.applyTargetAttrs(),void 0===t.target&&void 0===t.trigger&&void 0===t.virtualTriggering&&e===this.options.target&&i===this.options.trigger.join(",")&&s===this.options.virtualTriggering||this.bindTriggerEvents(),!this.node||void 0===t.appendTo&&void 0===t.container&&void 0===t.teleported&&o===this.options.appendTo&&n===this.options.container||this.attachNode(),this.node&&(e=this.prefix,this.node.style.position=this.strategy,d.removeClass(this.node,"".concat(e,"tooltip--dark")),d.removeClass(this.node,"".concat(e,"tooltip--light")),d.addClass(this.node,"".concat(e,"tooltip--").concat(this.options.effect)),this.options.enterable?d.addClass(this.node,"".concat(e,"tooltip--enterable")):d.removeClass(this.node,"".concat(e,"tooltip--enterable")),this.arrowNode&&(this.arrowNode.style.display=this.options.showArrow?"":"none"),this.options.ariaLabel&&d.setAttr(this.node,{"aria-label":this.options.ariaLabel}),this.options.popperClass&&d.addClass(this.node,this.options.popperClass),this.options.popperStyle&&this.applyPopperStyle(this.node),this.isOpen)&&(this.applyContent(),this.updatePosition()),this.options.disabled?this.doHide():this.controlled&&(this.options.visible?this.doOpen():this.doHide())},p.prototype.on=function(t,e){return this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(e),this},p.prototype.off=function(t,e){var i=this.listeners[t];return i&&(this.listeners[t]=e?i.filter(function(t){return t!==e}):[]),this},p.prototype.destroy=function(){this.clearTimers(),this.unbindTriggerEvents(),this.unbindGlobalEvents(),this.unbindPopperEvents(),this.setAriaDescribedBy(!1),this.destroyNode(),this.currentContent=void 0,this.imperativeAnchor=null,this.isOpen=!1,this.listeners={},this.controlled=!1};var s=p;function p(t){void 0===t&&(t={});var e=this;this.node=null,this.contentNode=null,this.arrowNode=null,this.isOpen=!1,this.controlled=!1,this.currentContent=void 0,this.imperativeAnchor=null,this.prevAriaDescribedBy=null,this.showTimer=null,this.hideTimer=null,this.autoCloseTimer=null,this.positionFrame=null,this.globalBound=!1,this.triggerListeners=[],this.targetAttrEl=null,this.appliedTargetAttrs={},this.popperListeners=[],this.listeners={},this.scheduleUpdate=function(){var t;null===e.positionFrame&&(t="function"==typeof requestAnimationFrame?requestAnimationFrame:function(t){return setTimeout(function(){return t(Date.now())},16)},e.positionFrame=t(function(){e.positionFrame=null,e.updatePosition()}))},this.handleDocumentKeydown=function(t){"Escape"===t.key&&e.isOpen&&e.doHide(t)},this.clickOutsideUnbind=null,this.options=d.extend({prefix:d.DEFAULT_PREFIX,rawContent:!1,effect:"dark",placement:"bottom",fallbackPlacements:[],disabled:!1,offset:12,arrowOffset:5,showArrow:!0,showAfter:0,hideAfter:200,autoClose:0,popperClass:"",popperStyle:"",teleported:!0,enterable:!0,triggerKeys:["Enter","Space"],persistent:!0,transition:"",ariaLabel:"",focusOnTarget:!1,popperOptions:{},className:""},t),this.options.trigger=r(t.trigger),this.options.popperOptions=t.popperOptions||{},this.options.triggerKeys=t.triggerKeys||["Enter","Space"],this.controlled=Object.prototype.hasOwnProperty.call(t,"visible")&&d.isBoolean(t.visible),this.currentContent=t.content,this.bindTriggerEvents(),this.controlled&&this.options.visible&&this.doOpen()}Object.defineProperty(t,"isTextTruncated",{enumerable:!0,get:function(){return d.isTextTruncated}}),t.Tooltip=s,t.default=s,Object.defineProperty(t,"__esModule",{value:!0})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ew-color-picker/tooltip",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.20",
|
|
4
4
|
"description": "Standalone tooltip utility used by ew-color-picker plugins",
|
|
5
5
|
"main": "dist/tooltip.min.js",
|
|
6
6
|
"module": "dist/tooltip.esm.js",
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
"author": "eveningwater(854806732@qq.com)",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@ew-color-picker/utils": "^2.0.
|
|
21
|
+
"@ew-color-picker/utils": "^2.0.20"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"rollup": "^3.0.0",
|
|
25
25
|
"rollup-plugin-typescript2": "^0.34.0",
|
|
26
26
|
"typescript": "^4.9.0",
|
|
27
27
|
"rimraf": "^3.0.2",
|
|
28
|
-
"@ew-color-picker/utils": "2.0.
|
|
28
|
+
"@ew-color-picker/utils": "2.0.20"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|