rabbit-simple-ui
Version:
A simple UI component library based on JavaScript
992 lines (933 loc) • 419 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define("rabbit", [], factory);
else if(typeof exports === 'object')
exports["rabbit"] = factory();
else
root["rabbit"] = factory();
})(self, function() {
return /******/ (function() { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ "./node_modules/dayjs/dayjs.min.js":
/*!*****************************************!*\
!*** ./node_modules/dayjs/dayjs.min.js ***!
\*****************************************/
/***/ (function(module) {
!function(t,e){ true?module.exports=e():0}(this,function(){"use strict";var t="millisecond",e="second",n="minute",r="hour",i="day",s="week",u="month",a="quarter",o="year",f="date",h=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,c=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,d={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_")},$=function(t,e,n){var r=String(t);return!r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},l={s:$,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return(e<=0?"+":"-")+$(r,2,"0")+":"+$(i,2,"0")},m:function t(e,n){if(e.date()<n.date())return-t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),i=e.clone().add(r,u),s=n-i<0,a=e.clone().add(r+(s?-1:1),u);return+(-(r+(n-i)/(s?i-a:a-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(h){return{M:u,y:o,w:s,d:i,D:f,h:r,m:n,s:e,ms:t,Q:a}[h]||String(h||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},y="en",M={};M[y]=d;var m=function(t){return t instanceof S},D=function(t,e,n){var r;if(!t)return y;if("string"==typeof t)M[t]&&(r=t),e&&(M[t]=e,r=t);else{var i=t.name;M[i]=t,r=i}return!n&&r&&(y=r),r||!n&&y},v=function(t,e){if(m(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new S(n)},g=l;g.l=D,g.i=m,g.w=function(t,e){return v(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var S=function(){function d(t){this.$L=D(t.locale,null,!0),this.parse(t)}var $=d.prototype;return $.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(g.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match(h);if(r){var i=r[2]-1||0,s=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.$x=t.x||{},this.init()},$.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},$.$utils=function(){return g},$.isValid=function(){return!("Invalid Date"===this.$d.toString())},$.isSame=function(t,e){var n=v(t);return this.startOf(e)<=n&&n<=this.endOf(e)},$.isAfter=function(t,e){return v(t)<this.startOf(e)},$.isBefore=function(t,e){return this.endOf(e)<v(t)},$.$g=function(t,e,n){return g.u(t)?this[e]:this.set(n,t)},$.unix=function(){return Math.floor(this.valueOf()/1e3)},$.valueOf=function(){return this.$d.getTime()},$.startOf=function(t,a){var h=this,c=!!g.u(a)||a,d=g.p(t),$=function(t,e){var n=g.w(h.$u?Date.UTC(h.$y,e,t):new Date(h.$y,e,t),h);return c?n:n.endOf(i)},l=function(t,e){return g.w(h.toDate()[t].apply(h.toDate("s"),(c?[0,0,0,0]:[23,59,59,999]).slice(e)),h)},y=this.$W,M=this.$M,m=this.$D,D="set"+(this.$u?"UTC":"");switch(d){case o:return c?$(1,0):$(31,11);case u:return c?$(1,M):$(0,M+1);case s:var v=this.$locale().weekStart||0,S=(y<v?y+7:y)-v;return $(c?m-S:m+(6-S),M);case i:case f:return l(D+"Hours",0);case r:return l(D+"Minutes",1);case n:return l(D+"Seconds",2);case e:return l(D+"Milliseconds",3);default:return this.clone()}},$.endOf=function(t){return this.startOf(t,!1)},$.$set=function(s,a){var h,c=g.p(s),d="set"+(this.$u?"UTC":""),$=(h={},h[i]=d+"Date",h[f]=d+"Date",h[u]=d+"Month",h[o]=d+"FullYear",h[r]=d+"Hours",h[n]=d+"Minutes",h[e]=d+"Seconds",h[t]=d+"Milliseconds",h)[c],l=c===i?this.$D+(a-this.$W):a;if(c===u||c===o){var y=this.clone().set(f,1);y.$d[$](l),y.init(),this.$d=y.set(f,Math.min(this.$D,y.daysInMonth())).$d}else $&&this.$d[$](l);return this.init(),this},$.set=function(t,e){return this.clone().$set(t,e)},$.get=function(t){return this[g.p(t)]()},$.add=function(t,a){var f,h=this;t=Number(t);var c=g.p(a),d=function(e){var n=v(h);return g.w(n.date(n.date()+Math.round(e*t)),h)};if(c===u)return this.set(u,this.$M+t);if(c===o)return this.set(o,this.$y+t);if(c===i)return d(1);if(c===s)return d(7);var $=(f={},f[n]=6e4,f[r]=36e5,f[e]=1e3,f)[c]||1,l=this.$d.getTime()+t*$;return g.w(l,this)},$.subtract=function(t,e){return this.add(-1*t,e)},$.format=function(t){var e=this;if(!this.isValid())return"Invalid Date";var n=t||"YYYY-MM-DDTHH:mm:ssZ",r=g.z(this),i=this.$locale(),s=this.$H,u=this.$m,a=this.$M,o=i.weekdays,f=i.months,h=function(t,r,i,s){return t&&(t[r]||t(e,n))||i[r].substr(0,s)},d=function(t){return g.s(s%12||12,t,"0")},$=i.meridiem||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r},l={YY:String(this.$y).slice(-2),YYYY:this.$y,M:a+1,MM:g.s(a+1,2,"0"),MMM:h(i.monthsShort,a,f,3),MMMM:h(f,a),D:this.$D,DD:g.s(this.$D,2,"0"),d:String(this.$W),dd:h(i.weekdaysMin,this.$W,o,2),ddd:h(i.weekdaysShort,this.$W,o,3),dddd:o[this.$W],H:String(s),HH:g.s(s,2,"0"),h:d(1),hh:d(2),a:$(s,u,!0),A:$(s,u,!1),m:String(u),mm:g.s(u,2,"0"),s:String(this.$s),ss:g.s(this.$s,2,"0"),SSS:g.s(this.$ms,3,"0"),Z:r};return n.replace(c,function(t,e){return e||l[t]||r.replace(":","")})},$.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},$.diff=function(t,f,h){var c,d=g.p(f),$=v(t),l=6e4*($.utcOffset()-this.utcOffset()),y=this-$,M=g.m(this,$);return M=(c={},c[o]=M/12,c[u]=M,c[a]=M/3,c[s]=(y-l)/6048e5,c[i]=(y-l)/864e5,c[r]=y/36e5,c[n]=y/6e4,c[e]=y/1e3,c)[d]||y,h?M:g.a(M)},$.daysInMonth=function(){return this.endOf(u).$D},$.$locale=function(){return M[this.$L]},$.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=D(t,e,!0);return r&&(n.$L=r),n},$.clone=function(){return g.w(this.$d,this)},$.toDate=function(){return new Date(this.valueOf())},$.toJSON=function(){return this.isValid()?this.toISOString():null},$.toISOString=function(){return this.$d.toISOString()},$.toString=function(){return this.$d.toUTCString()},d}(),p=S.prototype;return v.prototype=p,[["$ms",t],["$s",e],["$m",n],["$H",r],["$W",i],["$M",u],["$y",o],["$D",f]].forEach(function(t){p[t[1]]=function(e){return this.$g(e,t[0],t[1])}}),v.extend=function(t,e){return t.$i||(t(e,S,v),t.$i=!0),v},v.locale=D,v.isDayjs=m,v.unix=function(t){return v(1e3*t)},v.en=M[y],v.Ls=M,v.p={},v});
/***/ }),
/***/ "./node_modules/dayjs/locale/zh-cn.js":
/*!********************************************!*\
!*** ./node_modules/dayjs/locale/zh-cn.js ***!
\********************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
!function(_,e){ true?module.exports=e(__webpack_require__(/*! dayjs */ "./node_modules/dayjs/dayjs.min.js")):0}(this,function(_){"use strict";_=_&&_.hasOwnProperty("default")?_.default:_;var e={name:"zh-cn",weekdays:"星期日_星期一_星期二_星期三_星期四_星期五_星期六".split("_"),weekdaysShort:"周日_周一_周二_周三_周四_周五_周六".split("_"),weekdaysMin:"日_一_二_三_四_五_六".split("_"),months:"一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月".split("_"),monthsShort:"1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月".split("_"),ordinal:function(_,e){switch(e){case"W":return _+"周";default:return _+"日"}},weekStart:1,yearStart:4,formats:{LT:"HH:mm",LTS:"HH:mm:ss",L:"YYYY/MM/DD",LL:"YYYY年M月D日",LLL:"YYYY年M月D日Ah点mm分",LLLL:"YYYY年M月D日ddddAh点mm分",l:"YYYY/M/D",ll:"YYYY年M月D日",lll:"YYYY年M月D日 HH:mm",llll:"YYYY年M月D日dddd HH:mm"},relativeTime:{future:"%s内",past:"%s前",s:"几秒",m:"1 分钟",mm:"%d 分钟",h:"1 小时",hh:"%d 小时",d:"1 天",dd:"%d 天",M:"1 个月",MM:"%d 个月",y:"1 年",yy:"%d 年"},meridiem:function(_,e){var t=100*_+e;return t<600?"凌晨":t<900?"早上":t<1100?"上午":t<1300?"中午":t<1800?"下午":"晚上"}};return _.locale(e,null,!0),e});
/***/ }),
/***/ "./node_modules/dayjs/plugin/relativeTime.js":
/*!***************************************************!*\
!*** ./node_modules/dayjs/plugin/relativeTime.js ***!
\***************************************************/
/***/ (function(module) {
!function(r,t){ true?module.exports=t():0}(this,function(){"use strict";return function(r,t,e){r=r||{};var n=t.prototype,o={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function i(r,t,e,o){return n.fromToBase(r,t,e,o)}e.en.relativeTime=o,n.fromToBase=function(t,n,i,d,u){for(var a,f,s,l=i.$locale().relativeTime||o,h=r.thresholds||[{l:"s",r:44,d:"second"},{l:"m",r:89},{l:"mm",r:44,d:"minute"},{l:"h",r:89},{l:"hh",r:21,d:"hour"},{l:"d",r:35},{l:"dd",r:25,d:"day"},{l:"M",r:45},{l:"MM",r:10,d:"month"},{l:"y",r:17},{l:"yy",d:"year"}],m=h.length,c=0;c<m;c+=1){var y=h[c];y.d&&(a=d?e(t).diff(i,y.d,!0):i.diff(t,y.d,!0));var p=(r.rounding||Math.round)(Math.abs(a));if(s=a>0,p<=y.r||!y.r){p<=1&&c>0&&(y=h[c-1]);var v=l[y.l];u&&(p=u(""+p)),f="string"==typeof v?v.replace("%d",p):v(p,n,y.l,s);break}}if(n)return f;var M=s?l.future:l.past;return"function"==typeof M?M(f):M.replace("%s",f)},n.to=function(r,t){return i(r,t,this,!0)},n.from=function(r,t){return i(r,t,this)};var d=function(r){return r.$u?e.utc():e()};n.toNow=function(r){return this.to(d(this),r)},n.fromNow=function(r){return this.from(d(this),r)}}});
/***/ }),
/***/ "./src/build-umd.ts":
/*!***************************************!*\
!*** ./src/build-umd.ts + 82 modules ***!
\***************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
"default": function() { return /* binding */ build_umd; }
});
// NAMESPACE OBJECT: ./src/rabbit-simple-ui.ts
var rabbit_simple_ui_namespaceObject = {};
__webpack_require__.r(rabbit_simple_ui_namespaceObject);
__webpack_require__.d(rabbit_simple_ui_namespaceObject, {
"Affix": function() { return components_affix; },
"Alert": function() { return components_alert; },
"Avatar": function() { return components_avatar; },
"BackTop": function() { return components_back_top; },
"Badge": function() { return components_badge; },
"Breadcrumb": function() { return components_breadcrumb; },
"Button": function() { return components_button; },
"Card": function() { return components_card; },
"Carousel": function() { return components_carousel; },
"Checkbox": function() { return components_checkbox; },
"Circle": function() { return components_circle; },
"Collapse": function() { return components_collapse; },
"CountDown": function() { return components_count_down; },
"Divider": function() { return components_divider; },
"Drawer": function() { return components_drawer; },
"Dropdown": function() { return components_dropdown; },
"Empty": function() { return components_empty; },
"InputNumber": function() { return components_input_number; },
"Jumbotron": function() { return components_jumbotron; },
"Loading": function() { return components_loading_bar; },
"Message": function() { return components_message; },
"MiniModal": function() { return components_mini_modal; },
"Modal": function() { return components_modal; },
"Notice": function() { return components_notice; },
"PageHeader": function() { return components_page_header; },
"Poptip": function() { return components_poptip; },
"Progress": function() { return components_progress; },
"Radio": function() { return components_radio; },
"Result": function() { return components_result; },
"Skeleton": function() { return components_skeleton; },
"Spin": function() { return components_spin; },
"Steps": function() { return components_steps; },
"Switch": function() { return components_switch; },
"Tabs": function() { return components_tabs; },
"Tag": function() { return components_tag; },
"Time": function() { return components_time; },
"Timeline": function() { return components_timeline; },
"Tooltip": function() { return components_tooltip; }
});
// EXTERNAL MODULE: ./src/dom-utils/index.ts + 5 modules
var dom_utils = __webpack_require__("./src/dom-utils/index.ts");
// EXTERNAL MODULE: ./src/utils/index.ts + 4 modules
var utils = __webpack_require__("./src/utils/index.ts");
// EXTERNAL MODULE: ./src/components/prefix.ts
var prefix = __webpack_require__("./src/components/prefix.ts");
;// CONCATENATED MODULE: ./src/components/affix/affix.ts
/* eslint-disable @typescript-eslint/no-non-null-assertion */
function getScroll(target, top) {
var prop = top ? 'pageYOffset' : 'pageXOffset';
var method = top ? 'scrollTop' : 'scrollLeft';
var ret = target[prop];
if (typeof ret !== 'number') {
ret = window.document.documentElement[method];
}
return ret;
}
function getOffset(element) {
var rect = element.getBoundingClientRect();
var scrollTop = getScroll(window, true);
var scrollLeft = getScroll(window);
var docEl = window.document.body;
var clientTop = docEl.clientTop || 0;
var clientLeft = docEl.clientLeft || 0;
return {
top: rect.top + scrollTop - clientTop,
left: rect.left + scrollLeft - clientLeft
};
}
var Affix = /** @class */ (function () {
function Affix() {
this.VERSION = 'v1.0';
this.COMPONENTS = (0,dom_utils.$el)('r-affix', { all: true });
this._create(this.COMPONENTS);
}
Affix.prototype.config = function (el) {
var target = (0,dom_utils.$el)(el);
var _a = Affix.prototype._attrs(target), offsetTop = _a.offsetTop, offsetBottom = _a.offsetBottom;
var elOffset = getOffset(target);
var elHeight = target.offsetHeight;
var windowHeight = window.innerHeight;
var affixed = false, offsetType = 'top';
if (offsetBottom >= 0) {
offsetType = 'bottom';
}
return {
events: function (_a) {
var onChange = _a.onChange;
var handler = function () {
var isAffix = target.classList.contains("" + prefix.default.affix);
var scrollTop = getScroll(window, true);
// 固定到顶部时触发事件
if (elOffset.top - offsetTop < scrollTop && offsetType == 'top' && !isAffix) {
affixed = true;
onChange && utils.type.isFn(onChange, affixed);
}
else if (elOffset.top - offsetTop > scrollTop &&
offsetType == 'top' &&
affixed) {
affixed = false;
onChange && utils.type.isFn(onChange, affixed);
}
// 固定到底部时触发事件
if (elOffset.top + offsetBottom + elHeight > scrollTop + windowHeight &&
offsetType == 'bottom' &&
!affixed) {
affixed = true;
onChange && utils.type.isFn(onChange, affixed);
}
else if (elOffset.top + offsetBottom + elHeight < scrollTop + windowHeight &&
offsetType == 'bottom' &&
affixed) {
affixed = false;
onChange && utils.type.isFn(onChange, affixed);
}
};
handler();
// 这里 useCapture 选项设置为 true 解决了被下面同样的滚动监听覆盖的 bug
// 相当于提高了事件触发优先级
window.addEventListener('scroll', handler, true);
window.addEventListener('resize', handler, true);
}
};
};
Affix.prototype._create = function (COMPONENTS) {
var _this = this;
COMPONENTS.forEach(function (node) {
var _a = _this._attrs(node), offsetTop = _a.offsetTop, offsetBottom = _a.offsetBottom, useCapture = _a.useCapture;
var wrapper = (0,dom_utils.createElem)('div');
var cloneElm = _this._createCloneElm(wrapper);
node.after(wrapper);
wrapper.appendChild(node);
_this._handleScroll(node, cloneElm, offsetTop, offsetBottom, useCapture);
(0,dom_utils.removeAttrs)(node, ['offset-top', 'offset-bottom', 'use-capture']);
});
};
Affix.prototype._createCloneElm = function (node) {
var element = (0,dom_utils.createElem)('div');
(0,dom_utils.setCss)(element, 'display', 'none');
node.after(element);
return element;
};
Affix.prototype._handleScroll = function (node, cloneElm, offsetTop, offsetBottom, useCapture) {
var container = node.parentElement;
var elOffset = getOffset(node);
var elHeight = node.offsetHeight;
var windowHeight = window.innerHeight;
var affix = false, top, left, width, bottom, offsetType = 'top', cloneElmWidth, cloneElmHeight, display;
if (offsetBottom >= 0) {
offsetType = 'bottom';
}
var scroll = function () {
var isAffix = node.classList.contains("" + prefix.default.affix);
var scrollTop = getScroll(window, true);
// 固定到顶部
if (elOffset.top - offsetTop < scrollTop && offsetType == 'top' && !isAffix) {
affix = true;
display = '';
top = offsetTop + "px";
left = elOffset.left + "px";
width = container.offsetWidth + "px";
cloneElmWidth = node.clientWidth + "px";
cloneElmHeight = node.clientHeight + "px";
node.classList.add("" + prefix.default.affix);
}
else if (elOffset.top - offsetTop > scrollTop && offsetType == 'top' && affix) {
top = '';
left = '';
width = '';
affix = false;
display = 'none';
cloneElmWidth = '';
cloneElmHeight = '';
node.classList.remove("" + prefix.default.affix);
}
// 固定到底部
if (elOffset.top + offsetBottom + elHeight > scrollTop + windowHeight &&
offsetType == 'bottom' &&
!affix) {
affix = true;
left = elOffset.left + "px";
width = container.offsetWidth + "px";
bottom = offsetBottom + "px";
node.classList.add("" + prefix.default.affix);
}
else if (elOffset.top + offsetBottom + elHeight < scrollTop + windowHeight &&
offsetType == 'bottom' &&
affix) {
affix = false;
left = '';
width = '';
bottom = '';
node.classList.remove("" + prefix.default.affix);
}
(0,dom_utils.setCss)(node, 'top', top);
(0,dom_utils.setCss)(node, 'left', left);
(0,dom_utils.setCss)(node, 'width', width);
(0,dom_utils.setCss)(node, 'bottom', bottom);
(0,dom_utils.setCss)(cloneElm, 'width', cloneElmWidth);
(0,dom_utils.setCss)(cloneElm, 'height', cloneElmHeight);
(0,dom_utils.setCss)(cloneElm, 'display', display);
};
scroll();
window.addEventListener('scroll', scroll, useCapture);
window.addEventListener('resize', scroll, useCapture);
};
Affix.prototype._attrs = function (node) {
return {
offsetTop: (0,dom_utils.getNumTypeAttr)(node, 'offset-top', 0),
offsetBottom: (0,dom_utils.getNumTypeAttr)(node, 'offset-bottom'),
useCapture: (0,dom_utils.getBooleanTypeAttr)(node, 'use-capture')
};
};
return Affix;
}());
/* harmony default export */ var affix = (Affix);
;// CONCATENATED MODULE: ./src/components/affix/index.ts
/* harmony default export */ var components_affix = (affix);
// EXTERNAL MODULE: ./src/mixins/index.ts + 63 modules
var mixins = __webpack_require__("./src/mixins/index.ts");
;// CONCATENATED MODULE: ./src/components/alert/alert.ts
/* eslint-disable @typescript-eslint/no-non-null-assertion */
var Alert = /** @class */ (function () {
function Alert() {
this.VERSION = 'v1.0';
this.COMPONENTS = (0,dom_utils.$el)('r-alert', { all: true });
this._create(this.COMPONENTS);
}
Alert.prototype.config = function (el) {
var target = (0,dom_utils.$el)(el);
(0,utils.validComps)(target, 'alert');
var AlertTitle = target.querySelector("." + prefix.default.alert + "-title");
var AlertIcon = target.querySelector("." + prefix.default.alert + "-icon");
return {
get title() {
return (0,dom_utils.setHtml)(AlertTitle);
},
set title(newVal) {
if (newVal && !utils.type.isStr(newVal))
return;
(0,dom_utils.setHtml)(AlertTitle, newVal);
},
get icon() {
return (0,dom_utils.setHtml)(AlertIcon);
},
set icon(newVal) {
if (!AlertIcon) {
(0,mixins.warn)("You need to set the \"show-icon\" attribute to \"true\" --> \"" + el + "\"");
return;
}
if (newVal && !utils.type.isStr(newVal))
return;
(0,dom_utils.setHtml)(AlertIcon, newVal);
},
events: function (_a) {
var onClose = _a.onClose;
var AlertClose = target.querySelector("." + prefix.default.alert + "-close");
if (!AlertClose)
return;
(0,dom_utils.bind)(AlertClose, 'click', function (event) { return onClose && utils.type.isFn(onClose, event); });
}
};
};
Alert.prototype._create = function (COMPONENTS) {
var _this = this;
COMPONENTS.forEach(function (node) {
if ((0,mixins.moreThanOneNode)(node))
return;
var _a = _this._attrs(node), icon = _a.icon, type = _a.type, title = _a.title, closable = _a.closable, banner = _a.banner, showIcon = _a.showIcon, closeText = _a.closeText;
var placeholderNode = node.firstElementChild;
_this._setMainTemplate(node, title);
_this._setBanner(node, banner);
_this._setIconType(node, type, showIcon, icon, placeholderNode);
_this._setDescription(node, placeholderNode);
_this._setClosable(node, closable, closeText);
_this._handleClose(node);
(0,dom_utils.removeAttrs)(node, ['title', 'icon', 'banner', 'closable', 'close-text', 'show-icon']);
});
};
Alert.prototype._setMainTemplate = function (node, title) {
var template = "\n <div class=\"" + prefix.default.alert + "-title\">" + title + "</div>\n <div class=\"" + prefix.default.alert + "-desc\"></div>\n ";
(0,dom_utils.setHtml)(node, template);
};
Alert.prototype._setBanner = function (node, banner) {
if (!banner)
return;
node.classList.add(prefix.default.alert + "-with-banner");
};
Alert.prototype._setIconType = function (node, type, showIcon, icon, desc) {
if (!showIcon)
return;
node.classList.add(prefix.default.alert + "-with-icon");
var AlertIconWrap = (0,dom_utils.createElem)('span');
AlertIconWrap.className = prefix.default.alert + "-icon";
if (icon) {
(0,dom_utils.setHtml)(AlertIconWrap, icon);
}
else {
// 默认为 info 图标
var iconType = 'information-circle';
switch (type) {
case 'success':
iconType = 'checkmark-circle';
break;
case 'warning':
iconType = 'alert';
break;
case 'error':
iconType = 'close-circle';
break;
}
if (desc) {
iconType += '-outline';
}
var AlertIcon = "<i class=\"" + prefix.default.icon + " " + prefix.default.icon + "-ios-" + iconType + "\"></i>";
(0,dom_utils.setHtml)(AlertIconWrap, AlertIcon);
}
node.appendChild(AlertIconWrap);
};
Alert.prototype._setDescription = function (node, placeholderNode) {
if (!placeholderNode)
return;
node.classList.add(prefix.default.alert + "-with-desc");
var AlertDesc = node.querySelector("." + prefix.default.alert + "-desc");
AlertDesc.appendChild(placeholderNode);
};
Alert.prototype._setClosable = function (node, closable, closeText) {
if (!closable)
return;
var AlertClose = "\n <a class=\"" + prefix.default.alert + "-close\">\n " + (!closeText ? " <i class=\"" + prefix.default.icon + " " + prefix.default.icon + "-ios-close\"></i>" : closeText) + "\n </a>";
node.insertAdjacentHTML('beforeend', AlertClose);
};
Alert.prototype._handleClose = function (node) {
var AlertIcon = node.querySelector("." + prefix.default.alert + "-close");
if (!AlertIcon)
return;
(0,dom_utils.bind)(AlertIcon, 'click', function () { return (0,utils.destroyElem)(node, { fadeOut: true, destroy: true }); });
};
Alert.prototype._attrs = function (node) {
return {
icon: (0,dom_utils.getStrTypeAttr)(node, 'icon', ''),
type: (0,dom_utils.getStrTypeAttr)(node, 'type', 'info'),
title: (0,dom_utils.getStrTypeAttr)(node, 'title', ''),
closeText: (0,dom_utils.getStrTypeAttr)(node, 'close-text', ''),
banner: (0,dom_utils.getBooleanTypeAttr)(node, 'banner'),
closable: (0,dom_utils.getBooleanTypeAttr)(node, 'closable'),
showIcon: (0,dom_utils.getBooleanTypeAttr)(node, 'show-icon')
};
};
return Alert;
}());
/* harmony default export */ var alert_alert = (Alert);
;// CONCATENATED MODULE: ./src/components/alert/index.ts
/* harmony default export */ var components_alert = (alert_alert);
;// CONCATENATED MODULE: ./src/components/avatar/avatar.ts
/* eslint-disable @typescript-eslint/no-non-null-assertion */
var Avatar = /** @class */ (function () {
function Avatar() {
this.VERSION = 'v1.0';
this.COMPONENTS = (0,dom_utils.$el)('r-avatar', { all: true });
this._create(this.COMPONENTS);
}
Avatar.prototype.config = function (el) {
var target = (0,dom_utils.$el)(el);
(0,utils.validComps)(target, 'avatar');
var AvatarImage = target.querySelector('img');
return {
events: function (_a) {
var onError = _a.onError;
if (!AvatarImage) {
(0,mixins.warn)("Unable to add an event where the image failed to load for the current avatar --> \"" + el + "\"");
return;
}
(0,dom_utils.bind)(AvatarImage, 'error', function (event) { return onError && utils.type.isFn(onError, event); });
}
};
};
Avatar.prototype._create = function (COMPONENTS) {
var _this = this;
COMPONENTS.forEach(function (node) {
var _a = _this._attrs(node), icon = _a.icon, src = _a.src, alt = _a.alt, size = _a.size;
_this._setSize(node, size);
_this._setIcon(node, icon);
_this._setImage(node, src, alt);
_this._setText(node, icon, src);
(0,dom_utils.removeAttrs)(node, ['icon', 'src', 'alt']);
});
};
Avatar.prototype._setSize = function (node, size) {
if (!size)
return;
var _size = Number(size);
if (!_size)
return;
(0,dom_utils.setCss)(node, 'width', _size + "px");
(0,dom_utils.setCss)(node, 'height', _size + "px");
(0,dom_utils.setCss)(node, 'fontSize', _size / 2 + "px");
node.removeAttribute('size');
};
Avatar.prototype._setIcon = function (node, icon) {
if (!icon)
return;
node.classList.add(prefix.default.avatar + "-icon");
var AvatarIcon = "<i class=\"" + prefix.default.icon + " " + prefix.default.icon + "-" + icon + "\"></i>";
(0,dom_utils.setHtml)(node, AvatarIcon);
};
Avatar.prototype._setImage = function (node, src, alt) {
if (!src)
return;
node.classList.add(prefix.default.avatar + "-image");
var AvatarImage = "<img src=\"" + src + "\" alt=\"" + alt + "\" />";
(0,dom_utils.setHtml)(node, AvatarImage);
};
Avatar.prototype._setText = function (node, icon, src) {
if (icon || src)
return;
if (!(0,dom_utils.setHtml)(node))
return;
var text = (0,dom_utils.setHtml)(node);
var AvatarText = "<span class=\"" + prefix.default.avatar + "-string\">" + text + "</span>";
(0,dom_utils.setHtml)(node, AvatarText);
this._setScale(node);
};
// 防止字符型头像的字体溢出边界
Avatar.prototype._setScale = function (node) {
var children = node.querySelector("." + prefix.default.avatar + "-string");
if (!children)
return;
var avatarWidth = node.getBoundingClientRect().width;
var childrenWidth = children.offsetWidth;
if (avatarWidth - 8 < childrenWidth) {
var newScale = "scale(" + (avatarWidth - 8) / childrenWidth + ") translateX(-50%)";
(0,dom_utils.setCss)(children, 'transform', "" + newScale);
}
else {
(0,dom_utils.setCss)(children, 'transform', 'scale(1) translateX(-50%)');
}
};
Avatar.prototype._attrs = function (node) {
return {
icon: (0,dom_utils.getStrTypeAttr)(node, 'icon', ''),
src: (0,dom_utils.getStrTypeAttr)(node, 'src', ''),
alt: (0,dom_utils.getStrTypeAttr)(node, 'alt', ''),
size: (0,dom_utils.getStrTypeAttr)(node, 'size', '')
};
};
return Avatar;
}());
/* harmony default export */ var avatar = (Avatar);
;// CONCATENATED MODULE: ./src/components/avatar/index.ts
/* harmony default export */ var components_avatar = (avatar);
;// CONCATENATED MODULE: ./src/components/back-top/back-top.ts
var BackTop = /** @class */ (function () {
function BackTop() {
this.VERSION = 'v1.0';
this.COMPONENTS = (0,dom_utils.$el)('r-back-top', { all: true });
this._create(this.COMPONENTS);
}
BackTop.prototype._create = function (COMPONENTS) {
var _this = this;
COMPONENTS.forEach(function (node) {
var _a = _this._attrs(node), right = _a.right, bottom = _a.bottom, height = _a.height, duration = _a.duration;
_this._setRight(node, right);
_this._setBottom(node, bottom);
_this._setAppearance(node);
_this._handleScroll(node, height);
_this._handleClick(node, duration);
(0,dom_utils.removeAttrs)(node, ['right', 'bottom', 'height', 'duration']);
});
};
BackTop.prototype._setRight = function (node, right) {
(0,dom_utils.setCss)(node, 'right', right + "px");
};
BackTop.prototype._setBottom = function (node, bottom) {
(0,dom_utils.setCss)(node, 'bottom', bottom + "px");
};
BackTop.prototype._setAppearance = function (node) {
if ((0,dom_utils.setHtml)(node) && (0,dom_utils.setHtml)(node) !== ' ') {
(0,dom_utils.setHtml)(node, node.innerHTML);
}
else {
var template = "<div class=\"" + prefix.default.backtop + "-inner\">\n <i class=\"" + prefix.default.icon + " " + prefix.default.icon + "-ios-arrow-up\"></i>\n </div>";
(0,dom_utils.setHtml)(node, template);
}
};
BackTop.prototype._handleScroll = function (node, height) {
var visable = function (y) {
var scrollY = Math.floor(y);
var visibilityHeight = Math.floor(height);
// 判断页面是否滚动到指定显示的高度
scrollY >= visibilityHeight
? (0,dom_utils.setCss)(node, 'display', 'block')
: (0,dom_utils.setCss)(node, 'display', '');
};
(0,dom_utils.bind)(window, 'scroll', function () {
visable(window.scrollY);
});
};
BackTop.prototype._handleClick = function (node, duration) {
var _this = this;
(0,dom_utils.bind)(node, 'click', function () {
var sTop = document.documentElement.scrollTop || document.body.scrollTop;
_this._scrollTop(window, sTop, 0, duration);
});
};
BackTop.prototype._scrollTop = function (el, from, to, duration) {
if (!window.requestAnimationFrame) {
window.requestAnimationFrame =
window.webkitRequestAnimationFrame ||
// @ts-ignore
window.mozRequestAnimationFrame ||
// @ts-ignore
window.msRequestAnimationFrame ||
function (callback) {
return window.setTimeout(callback, 1000 / 60);
};
}
var difference = Math.abs(from - to);
var step = Math.ceil((difference / duration) * 25);
var scroll = function (start, end, step) {
var d = start + step > end ? end : start + step;
if (start <= end && d == 0)
return;
d = start - step < end ? end : start - step;
el === window ? window.scrollTo(d, d) : (el.scrollTop = d);
window.requestAnimationFrame(function () { return scroll(d, end, step); });
};
scroll(from, to, step);
};
BackTop.prototype._attrs = function (node) {
return {
right: (0,dom_utils.getNumTypeAttr)(node, 'right', 30),
bottom: (0,dom_utils.getNumTypeAttr)(node, 'bottom', 30),
height: (0,dom_utils.getNumTypeAttr)(node, 'height', 400),
duration: (0,dom_utils.getNumTypeAttr)(node, 'duration', 500)
};
};
return BackTop;
}());
/* harmony default export */ var back_top = (BackTop);
;// CONCATENATED MODULE: ./src/components/back-top/index.ts
/* harmony default export */ var components_back_top = (back_top);
;// CONCATENATED MODULE: ./src/components/badge/badge.ts
var Badge = /** @class */ (function () {
function Badge() {
this.VERSION = 'v1.0';
this.COMPONENTS = (0,dom_utils.$el)('r-badge', { all: true });
this._create(this.COMPONENTS);
}
Badge.prototype.config = function (el) {
var target = (0,dom_utils.$el)(el);
(0,utils.validComps)(target, 'badge');
var countContainer = target.querySelector("." + prefix.default.badge + "-count");
var dotContainer = target.querySelector("." + prefix.default.badge + "-dot");
var _a = Badge.prototype, _getMaxCount = _a._getMaxCount, _showZero = _a._showZero, _setMaxCount = _a._setMaxCount;
var maxCount = _getMaxCount(target);
var showZero = _showZero(target);
return {
get count() {
return countContainer === null || countContainer === void 0 ? void 0 : countContainer.textContent;
},
set count(newVal) {
if (countContainer && utils.type.isNum(newVal)) {
if (newVal > maxCount) {
_setMaxCount(countContainer, maxCount);
}
else {
(0,dom_utils.setText)(countContainer, "" + newVal);
if (newVal <= 0 && !showZero) {
(0,dom_utils.setCss)(countContainer, 'display', 'none');
}
else {
(0,dom_utils.setCss)(countContainer, 'display', '');
}
}
}
else {
(0,mixins.warn)("The count value of this badge cannot be set --> \"" + el + "\"");
}
},
get text() {
return countContainer === null || countContainer === void 0 ? void 0 : countContainer.textContent;
},
set text(newVal) {
if (!utils.type.isStr(newVal)) {
(0,mixins.warn)("The text value of this badge cannot be set --> \"" + el + "\"");
return;
}
(0,dom_utils.setText)(countContainer, newVal);
},
get dot() {
return dotContainer;
},
set dot(newVal) {
if (!dotContainer) {
(0,mixins.warn)("Unable to set this badge to dot --> \"" + el + "\"");
return;
}
if (utils.type.isBol(newVal) && newVal) {
(0,dom_utils.setCss)(dotContainer, 'display', '');
}
else {
(0,dom_utils.setCss)(dotContainer, 'display', 'none');
}
}
};
};
Badge.prototype._create = function (COMPONENTS) {
var _this = this;
COMPONENTS.forEach(function (node) {
_this._setCount(node);
_this._setStatusWithColor(node);
(0,dom_utils.removeAttrs)(node, [
'count',
'text',
'status',
'color',
'show-zero',
'max-count',
'dot'
]);
});
};
Badge.prototype._setCount = function (node) {
var count = this._getCount(node);
var maxCount = this._getMaxCount(node);
var BadgeCount = (0,dom_utils.createElem)('sup');
BadgeCount.className = prefix.default.badge + "-count";
if (count || count === 0) {
// 显示的数字大于maxCount时,显示${maxCount}+
if (count > maxCount) {
this._setMaxCount(BadgeCount, maxCount);
}
else {
// 数字为 0 时隐藏或者展示 Badge
if (count <= 0 && !this._showZero(node)) {
(0,dom_utils.setCss)(BadgeCount, 'display', 'none');
}
else {
(0,dom_utils.setText)(BadgeCount, "" + count);
}
}
this._setDot(node, BadgeCount);
}
if (!this._getStatus(node) && !this._getColor(node)) {
node.appendChild(BadgeCount);
// 状态点外观不需要设置为独立展示
this._setAlone(BadgeCount);
}
this._setText(node, BadgeCount);
this._setOffset(node, BadgeCount);
};
Badge.prototype._setMaxCount = function (node, maxCount) {
(0,dom_utils.setText)(node, maxCount + "+");
};
Badge.prototype._setDot = function (node, children) {
if (!this._showDot(node))
return;
// 设置为小红点则不显示任何计数内容
(0,dom_utils.setHtml)(children, '');
(0,dom_utils.setCss)(children, 'display', '');
children.className = prefix.default.badge + "-dot";
};
Badge.prototype._setText = function (parent, children) {
// 区分与标签属性 status 或 color 配合的 text 属性
if (!this._getStatus(parent) && !this._getColor(parent)) {
var text = this._getText(parent);
if (text) {
(0,dom_utils.setCss)(children, 'display', '');
(0,dom_utils.setText)(children, text);
}
}
};
Badge.prototype._setAlone = function (children) {
if (!children.previousElementSibling) {
children.classList.add(prefix.default.badge + "-count-alone");
}
};
Badge.prototype._setOffset = function (parent, children) {
var offset = this._getOffset(parent);
(0,dom_utils.setCss)(children, 'marginTop', (offset === null || offset === void 0 ? void 0 : offset.x) + "px");
(0,dom_utils.setCss)(children, 'marginRight', (offset === null || offset === void 0 ? void 0 : offset.y) + "px");
};
Badge.prototype._setStatusWithColor = function (node) {
var status = this._getStatus(node);
var color = this._getColor(node);
var text = this._getText(node);
if (!status && !color)
return;
var BadgeStatusDot = (0,dom_utils.createElem)('span');
var BadgeStatusText = (0,dom_utils.createElem)('span');
if ((text && status) || (text && color))
(0,dom_utils.setText)(BadgeStatusText, text);
var statusCls;
var colorCls = '';
status ? (statusCls = prefix.default.badge + "-status-" + status) : (statusCls = '');
// 设置更多预设的状态点颜色,或者自定义颜色
var colorType = [
'blue',
'green',
'red',
'yellow',
'magenta',
'volcano',
'orange',
'gold',
'lime',
'cyan',
'geekblue',
'purple'
];
if (colorType.includes(color)) {
colorCls = prefix.default.badge + "-status-" + color;
}
else {
(0,dom_utils.setCss)(BadgeStatusDot, 'backgroundColor', color);
}
BadgeStatusDot.className = prefix.default.badge + "-status-dot " + statusCls + " " + colorCls;
BadgeStatusText.className = prefix.default.badge + "-status-text";
node.append(BadgeStatusDot, BadgeStatusText);
};
Badge.prototype._getCount = function (node) {
return Number(node.getAttribute('count'));
};
Badge.prototype._getMaxCount = function (node) {
return Number(node.getAttribute('max-count')) || 99;
};
Badge.prototype._getOffset = function (node) {
// 转为真实数组,如果赋值是 offset = ['0','1'] 这样的则会报错
var offset = JSON.parse(node.getAttribute('offset') || '[]');
// 如果是数组,那么不论写了多少个值都只返回前两个
if (utils.type.isArr(offset) && offset.length > 0) {
return {
x: offset[0],
y: offset[1]
};
}
};
Badge.prototype._getStatus = function (node) {
return node.getAttribute('status') || '';
};
Badge.prototype._getColor = function (node) {
return node.getAttribute('color') || '';
};
Badge.prototype._getText = function (node) {
return node.getAttribute('text') || '';
};
Badge.prototype._showZero = function (node) {
return node.getAttribute('show-zero') === 'true';
};
Badge.prototype._showDot = function (node) {
return node.getAttribute('dot') === 'true';
};
return Badge;
}());
/* harmony default export */ var badge = (Badge);
;// CONCATENATED MODULE: ./src/components/badge/index.ts
/* harmony default export */ var components_badge = (badge);
;// CONCATENATED MODULE: ./src/components/breadcrumb/breadcrumb.ts
var Breadcrumb = /** @class */ (function () {
function Breadcrumb() {
this.VERSION = 'v1.0';
this.COMPONENTS = (0,dom_utils.$el)('r-breadcrumb', { all: true });
this._create(this.COMPONENTS);
}
Breadcrumb.prototype._create = function (COMPONENTS) {
var _this = this;
COMPONENTS.forEach(function (node) {
var separator = _this._attrs(node).separator;
_this._createItem(node, separator);
(0,dom_utils.removeAttrs)(node, ['separator']);
});
};
Breadcrumb.prototype._createItem = function (node, separator) {
var children = node.children;
var Fragment = document.createDocumentFragment();
Array.from(children).forEach(function (child) {
var Wrapper = (0,dom_utils.createElem)('span');
var Separator = (0,dom_utils.createElem)('span');
Separator.className = prefix.default.breadcrumb + "-item-separator";
// 设置分隔符
(0,dom_utils.setHtml)(Separator, "" + separator);
child.classList.add(prefix.default.breadcrumb + "-item-link");
// 初始化为行内块样式
(0,dom_utils.setCss)(child, 'display', 'inline-block');
Wrapper.append(child, Separator);
Fragment.appendChild(Wrapper);
});
node.appendChild(Fragment);
};
Breadcrumb.prototype._attrs = function (node) {
return {
separator: (0,dom_utils.getStrTypeAttr)(node, 'separator', '/')
};
};
return Breadcrumb;
}());
/* harmony default export */ var breadcrumb = (Breadcrumb);
;// CONCATENATED MODULE: ./src/components/breadcrumb/index.ts
/* harmony default export */ var components_breadcrumb = (breadcrumb);
;// CONCATENATED MODULE: ./src/components/button/button.ts
var Button = /** @class */ (function () {
function Button() {
this.VERSION = '1.1.1';
this.COMPONENTS = (0,dom_utils.$el)("." + prefix.default.button, { all: true });
this._getAllBtns(this.COMPONENTS);
}
Button.prototype.config = function (el) {
var target = typeof el === 'string' ? (0,dom_utils.$el)(el) : el;
(0,utils.validComps)(target, 'button');
return {
get loading() {
return this.loading;
},
set loading(newVal) {
if (newVal && !utils.type.isBol(newVal))
return;
Button.prototype._setLoading(target, false, newVal);
}
};
};
Button.prototype._getAllBtns = function (COMPONENTS) {
var _this = this;
COMPONENTS.forEach(function (node) {
var _a = _this._attrs(node), icon = _a.icon, loading = _a.loading;
_this._setIcon(node, icon);
_this._setLoading(node, true, loading);
(0,dom_utils.removeAttrs)(node, ['icon', 'loading']);
});
};
Button.prototype._setIcon = function (node, icon) {
if (!icon)
return;
if (node.innerHTML === '') {
node.classList.add(prefix.default.button + "-icon-only");
var ButtonIcon = "\n <i class=\"" + prefix.default.icon + " " + prefix.default.icon + "-" + icon + "\"></i>\n ";
(0,dom_utils.setHtml)(node, ButtonIcon);
}
else {
var Icon = (0,dom_utils.createElem)('i');
Icon.className = prefix.default.icon + " " + prefix.default.icon + "-" + icon;
node.prepend(Icon);
}
};
// 2021.5.23
// v1.1.0 修复按钮 loading 状态下加载中图标和原有图标并列显示的 bug
Button.prototype._setLoading = function (node, firstRender, loading) {
var _a;
var OriginalIcon = node.querySelector('.rab-icon');
var LoadingIcon = (0,dom_utils.createElem)('i');
LoadingIcon.className = "rab-load-loop " + prefix.default.icon + " " + prefix.default.icon + "-loading-solid";
if (loading) {
if (OriginalIcon)
(0,dom_utils.setCss)(OriginalIcon, 'display', 'none');
if (node.innerHTML === '')
node.classList.add(prefix.default.button + "-icon-only");
node.classList.add(prefix.default.button + "-loading");
node.prepend(LoadingIcon);
}
else {
if (firstRender)
return;
// 2021.6.18
// v1.1.1 修复在没有图标仅有文本的状态下,切换为loading状态并在状态结束后无法切换为原样 bug
// setCss(node.children[1], 'display', '');
if (node.children[1])
(0,dom_utils.setCss)(node.children[1], 'display', '');
if (node.classList.contains(prefix.default.button + "-loading"))
node.classList.remove(prefix.default.button + "-loading");
if (node.classList.contains(prefix.default.button + "-icon-only"))
node.classList.remove(prefix.default.button + "-icon-only");
(_a = node.firstElementChild) === null || _a === void 0 ? void 0 : _a.remove();
}
};
Button.prototype._attrs = function (node) {
return {
icon: (0,dom_utils.getStrTypeAttr)(node, 'icon', ''),
loading: (0,dom_utils.getBooleanTypeAttr)(node, 'loading')
};
};
return Button;
}());
/* harmony default export */ var button_button = (Button);
;// CONCATENATED MODULE: ./src/components/button/index.ts
/* harmony default export */ var components_button = (button_button)