UNPKG

balm-ui

Version:

A modular and customizable UI library based on Material Design and Vue 3

1 lines 15.4 kB
!function(e,t){"object"===typeof exports&&"object"===typeof module?module.exports=t(require("vue")):"function"===typeof define&&define.amd?define("UiProgress",["vue"],t):"object"===typeof exports?exports.UiProgress=t(require("vue")):e.UiProgress=t(e.Vue)}("undefined"!==typeof self?self:this,(function(e){return function(){"use strict";var t={744:function(e){var t=function(e){return function(e){return!!e&&"object"===typeof e}(e)&&!function(e){var t=Object.prototype.toString.call(e);return"[object RegExp]"===t||"[object Date]"===t||function(e){return e.$$typeof===r}(e)}(e)};var r="function"===typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function n(e,t){return!1!==t.clone&&t.isMergeableObject(e)?u((r=e,Array.isArray(r)?[]:{}),e,t):e;var r}function o(e,t,r){return e.concat(t).map((function(e){return n(e,r)}))}function s(e){return Object.keys(e).concat(function(e){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter((function(t){return Object.propertyIsEnumerable.call(e,t)})):[]}(e))}function i(e,t){try{return t in e}catch(r){return!1}}function a(e,t,r){var o={};return r.isMergeableObject(e)&&s(e).forEach((function(t){o[t]=n(e[t],r)})),s(t).forEach((function(s){(function(e,t){return i(e,t)&&!(Object.hasOwnProperty.call(e,t)&&Object.propertyIsEnumerable.call(e,t))})(e,s)||(i(e,s)&&r.isMergeableObject(t[s])?o[s]=function(e,t){if(!t.customMerge)return u;var r=t.customMerge(e);return"function"===typeof r?r:u}(s,r)(e[s],t[s],r):o[s]=n(t[s],r))})),o}function u(e,r,s){(s=s||{}).arrayMerge=s.arrayMerge||o,s.isMergeableObject=s.isMergeableObject||t,s.cloneUnlessOtherwiseSpecified=n;var i=Array.isArray(r);return i===Array.isArray(e)?i?s.arrayMerge(e,r,s):a(e,r,s):n(r,s)}u.all=function(e,t){if(!Array.isArray(e))throw new Error("first argument should be an array");return e.reduce((function(e,r){return u(e,r,t)}),{})};var c=u;e.exports=c},154:function(t){t.exports=e}},r={};function n(e){var o=r[e];if(void 0!==o)return o.exports;var s=r[e]={exports:{}};return t[e](s,s.exports,n),s.exports}n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)};var o={};n.d(o,{default:function(){return F}});var s=n(744),i=n.n(s);const a=/(?:^\[object\s(.*?)\]$)/;var u=e=>Object.prototype.toString.call(e).replace(a,"$1").toLowerCase();const c=e=>{let{componentProps:t,propName:r,props:n}=e,o=n[r];if("object"===u(o)){const e=t[r].default;t[r].default=()=>i()(e,o)}else Array.isArray(o)?t[r].default=()=>o:t[r].default=o},l=e=>{let{componentMixins:t,propName:r,props:n}=e;if(t.length){let e=t.length;for(;e--;)if(t[e].props&&void 0!==t[e].props[r]){c({componentProps:t[e].props,propName:r,props:n});break}}};var f=(e,t)=>{for(const r of Object.keys(t))e.props?void 0===e.props[r]?l({componentMixins:e.mixins,propName:r,props:t}):c({componentProps:e.props,propName:r,props:t}):l({componentMixins:e.mixins,propName:r,props:t})};var p=e=>{const t={install(t){f(e,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),t.component(e.name,e)}};return t},d=n(154),y=function(e,t){return y=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},y(e,t)};function m(e,t){if("function"!==typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}y(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var b=function(){return b=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},b.apply(this,arguments)};Object.create;function h(e){var t="function"===typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"===typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function g(e,t){var r="function"===typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,s=r.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(n=s.next()).done;)i.push(n.value)}catch(a){o={error:a}}finally{try{n&&!n.done&&(r=s.return)&&r.call(s)}finally{if(o)throw o.error}}return i}function A(e,t,r){if(r||2===arguments.length)for(var n,o=0,s=t.length;o<s;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}Object.create;"function"===typeof SuppressedError&&SuppressedError;var v=function(){function e(e){void 0===e&&(e={}),this.adapter=e}return Object.defineProperty(e,"cssClasses",{get:function(){return{}},enumerable:!1,configurable:!0}),Object.defineProperty(e,"strings",{get:function(){return{}},enumerable:!1,configurable:!0}),Object.defineProperty(e,"numbers",{get:function(){return{}},enumerable:!1,configurable:!0}),Object.defineProperty(e,"defaultAdapter",{get:function(){return{}},enumerable:!1,configurable:!0}),e.prototype.init=function(){},e.prototype.destroy=function(){},e}(),S=function(){function e(e,t){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];this.root=e,this.initialize.apply(this,A([],g(r))),this.foundation=void 0===t?this.getDefaultFoundation():t,this.foundation.init(),this.initialSyncWithDOM()}return e.attachTo=function(t){return new e(t,new v({}))},e.prototype.initialize=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]},e.prototype.getDefaultFoundation=function(){throw new Error("Subclasses must override getDefaultFoundation to return a properly configured foundation class")},e.prototype.initialSyncWithDOM=function(){},e.prototype.destroy=function(){this.foundation.destroy()},e.prototype.listen=function(e,t,r){this.root.addEventListener(e,t,r)},e.prototype.unlisten=function(e,t,r){this.root.removeEventListener(e,t,r)},e.prototype.emit=function(e,t,r){var n;void 0===r&&(r=!1),"function"===typeof CustomEvent?n=new CustomEvent(e,{bubbles:r,detail:t}):(n=document.createEvent("CustomEvent")).initCustomEvent(e,r,!1,t),this.root.dispatchEvent(n)},e}(),_={animation:{prefixed:"-webkit-animation",standard:"animation"},transform:{prefixed:"-webkit-transform",standard:"transform"},transition:{prefixed:"-webkit-transition",standard:"transition"}};function E(e){return Boolean(e.document)&&"function"===typeof e.document.createElement}var O={CLOSED_CLASS:"mdc-linear-progress--closed",CLOSED_ANIMATION_OFF_CLASS:"mdc-linear-progress--closed-animation-off",INDETERMINATE_CLASS:"mdc-linear-progress--indeterminate",REVERSED_CLASS:"mdc-linear-progress--reversed",ANIMATION_READY_CLASS:"mdc-linear-progress--animation-ready"},P={ARIA_HIDDEN:"aria-hidden",ARIA_VALUEMAX:"aria-valuemax",ARIA_VALUEMIN:"aria-valuemin",ARIA_VALUENOW:"aria-valuenow",BUFFER_BAR_SELECTOR:".mdc-linear-progress__buffer-bar",FLEX_BASIS:"flex-basis",PRIMARY_BAR_SELECTOR:".mdc-linear-progress__primary-bar"},L=.8367142,C=2.00611057,I=.37651913,R=.84386165,j=1.60277782,M=function(e){function t(r){var n=e.call(this,b(b({},t.defaultAdapter),r))||this;return n.observer=null,n}return m(t,e),Object.defineProperty(t,"cssClasses",{get:function(){return O},enumerable:!1,configurable:!0}),Object.defineProperty(t,"strings",{get:function(){return P},enumerable:!1,configurable:!0}),Object.defineProperty(t,"defaultAdapter",{get:function(){return{addClass:function(){},attachResizeObserver:function(){return null},forceLayout:function(){},getWidth:function(){return 0},hasClass:function(){return!1},setBufferBarStyle:function(){return null},setPrimaryBarStyle:function(){return null},setStyle:function(){},removeAttribute:function(){},removeClass:function(){},setAttribute:function(){}}},enumerable:!1,configurable:!0}),t.prototype.init=function(){var e=this;this.determinate=!this.adapter.hasClass(O.INDETERMINATE_CLASS),this.adapter.addClass(O.ANIMATION_READY_CLASS),this.progress=0,this.buffer=1,this.observer=this.adapter.attachResizeObserver((function(t){var r,n;if(!e.determinate)try{for(var o=h(t),s=o.next();!s.done;s=o.next()){var i=s.value;i.contentRect&&e.calculateAndSetDimensions(i.contentRect.width)}}catch(a){r={error:a}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}})),!this.determinate&&this.observer&&this.calculateAndSetDimensions(this.adapter.getWidth())},t.prototype.setDeterminate=function(e){if(this.determinate=e,this.determinate)return this.adapter.removeClass(O.INDETERMINATE_CLASS),this.adapter.setAttribute(P.ARIA_VALUENOW,this.progress.toString()),this.adapter.setAttribute(P.ARIA_VALUEMAX,"1"),this.adapter.setAttribute(P.ARIA_VALUEMIN,"0"),this.setPrimaryBarProgress(this.progress),void this.setBufferBarProgress(this.buffer);this.observer&&this.calculateAndSetDimensions(this.adapter.getWidth()),this.adapter.addClass(O.INDETERMINATE_CLASS),this.adapter.removeAttribute(P.ARIA_VALUENOW),this.adapter.removeAttribute(P.ARIA_VALUEMAX),this.adapter.removeAttribute(P.ARIA_VALUEMIN),this.setPrimaryBarProgress(1),this.setBufferBarProgress(1)},t.prototype.isDeterminate=function(){return this.determinate},t.prototype.setProgress=function(e){this.progress=e,this.determinate&&(this.setPrimaryBarProgress(e),this.adapter.setAttribute(P.ARIA_VALUENOW,e.toString()))},t.prototype.getProgress=function(){return this.progress},t.prototype.setBuffer=function(e){this.buffer=e,this.determinate&&this.setBufferBarProgress(e)},t.prototype.getBuffer=function(){return this.buffer},t.prototype.open=function(){this.adapter.removeClass(O.CLOSED_CLASS),this.adapter.removeClass(O.CLOSED_ANIMATION_OFF_CLASS),this.adapter.removeAttribute(P.ARIA_HIDDEN)},t.prototype.close=function(){this.adapter.addClass(O.CLOSED_CLASS),this.adapter.setAttribute(P.ARIA_HIDDEN,"true")},t.prototype.isClosed=function(){return this.adapter.hasClass(O.CLOSED_CLASS)},t.prototype.handleTransitionEnd=function(){this.adapter.hasClass(O.CLOSED_CLASS)&&this.adapter.addClass(O.CLOSED_ANIMATION_OFF_CLASS)},t.prototype.destroy=function(){e.prototype.destroy.call(this),this.observer&&this.observer.disconnect()},t.prototype.restartAnimation=function(){this.adapter.removeClass(O.ANIMATION_READY_CLASS),this.adapter.forceLayout(),this.adapter.addClass(O.ANIMATION_READY_CLASS)},t.prototype.setPrimaryBarProgress=function(e){var t="scaleX("+e+")",r="undefined"!==typeof window?function(e,t){if(E(e)&&t in _){var r=e.document.createElement("div"),n=_[t],o=n.standard,s=n.prefixed;return o in r.style?o:s}return t}(window,"transform"):"transform";this.adapter.setPrimaryBarStyle(r,t)},t.prototype.setBufferBarProgress=function(e){var t=100*e+"%";this.adapter.setBufferBarStyle(P.FLEX_BASIS,t)},t.prototype.calculateAndSetDimensions=function(e){var t=e*L,r=e*C,n=e*I,o=e*R,s=e*j;this.adapter.setStyle("--mdc-linear-progress-primary-half",t+"px"),this.adapter.setStyle("--mdc-linear-progress-primary-half-neg",-t+"px"),this.adapter.setStyle("--mdc-linear-progress-primary-full",r+"px"),this.adapter.setStyle("--mdc-linear-progress-primary-full-neg",-r+"px"),this.adapter.setStyle("--mdc-linear-progress-secondary-quarter",n+"px"),this.adapter.setStyle("--mdc-linear-progress-secondary-quarter-neg",-n+"px"),this.adapter.setStyle("--mdc-linear-progress-secondary-half",o+"px"),this.adapter.setStyle("--mdc-linear-progress-secondary-half-neg",-o+"px"),this.adapter.setStyle("--mdc-linear-progress-secondary-full",s+"px"),this.adapter.setStyle("--mdc-linear-progress-secondary-full-neg",-s+"px"),this.restartAnimation()},t}(v),N=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return m(t,e),t.attachTo=function(e){return new t(e)},Object.defineProperty(t.prototype,"determinate",{set:function(e){this.foundation.setDeterminate(e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"progress",{set:function(e){this.foundation.setProgress(e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"buffer",{set:function(e){this.foundation.setBuffer(e)},enumerable:!1,configurable:!0}),t.prototype.open=function(){this.foundation.open()},t.prototype.close=function(){this.foundation.close()},t.prototype.initialSyncWithDOM=function(){var e=this;this.root.addEventListener("transitionend",(function(){e.foundation.handleTransitionEnd()}))},t.prototype.getDefaultFoundation=function(){var e=this;return new M({addClass:function(t){e.root.classList.add(t)},forceLayout:function(){e.root.getBoundingClientRect()},setBufferBarStyle:function(t,r){var n=e.root.querySelector(M.strings.BUFFER_BAR_SELECTOR);n&&n.style.setProperty(t,r)},setPrimaryBarStyle:function(t,r){var n=e.root.querySelector(M.strings.PRIMARY_BAR_SELECTOR);n&&n.style.setProperty(t,r)},hasClass:function(t){return e.root.classList.contains(t)},removeAttribute:function(t){e.root.removeAttribute(t)},removeClass:function(t){e.root.classList.remove(t)},setAttribute:function(t,r){e.root.setAttribute(t,r)},setStyle:function(t,r){e.root.style.setProperty(t,r)},attachResizeObserver:function(t){var r=window.ResizeObserver;if(r){var n=new r(t);return n.observe(e.root),n}return null},getWidth:function(){return e.root.offsetWidth}})},t}(S);const w=[(0,d.createStaticVNode)('<div class="mdc-linear-progress__buffer"><div class="mdc-linear-progress__buffer-bar"></div><div class="mdc-linear-progress__buffer-dots"></div></div><div class="mdc-linear-progress__bar mdc-linear-progress__primary-bar"><span class="mdc-linear-progress__bar-inner"></span></div><div class="mdc-linear-progress__bar mdc-linear-progress__secondary-bar"><span class="mdc-linear-progress__bar-inner"></span></div>',3)],B={name:"MdcLinearProgress",customOptions:{}};var x=Object.assign(B,{setup(e,t){let{expose:r}=t;const n=(0,d.ref)(null);return r({mdcLinearProgress:n}),(e,t)=>((0,d.openBlock)(),(0,d.createElementBlock)("div",{ref_key:"mdcLinearProgress",ref:n,class:"mdc-linear-progress",role:"progressbar"},w,512))}}),D={VALUE:{MIN:0,MAX:1}};const T={active:{type:Boolean,default:!1},progress:{type:Number,default:0},label:String,closed:{type:Boolean,default:!1}};const U="UiProgress",V={name:U,customOptions:{name:U,UI_PROGRESS:D}};var F=p(Object.assign(V,{props:{...T,buffer:{type:Number,default:0}},setup(e){const t=e,r=(0,d.ref)(null),n=(0,d.reactive)({$linearProgress:null}),o=(0,d.computed)((()=>({"mdc-linear-progress--indeterminate":t.active,"mdc-linear-progress--closed":t.closed})));function s(e){n.$linearProgress&&e>=D.VALUE.MIN&&e<=D.VALUE.MAX?n.$linearProgress.buffer=e:console.warn(`[${U}]: The 'buffer' prop value should be between [0, 1]`)}return(0,d.watch)((()=>t.buffer),(e=>s(e))),(0,d.onMounted)((()=>{const e=r.value.mdcLinearProgress;n.$linearProgress=new N(e);const{setProgress:o}=function(e,t){function r(t){e&&t>=D.VALUE.MIN&&t<=D.VALUE.MAX?e.progress=t:console.warn("[UiProgress/UiSpinner]","The value should be between [0, 1]")}return(0,d.watch)((()=>t.progress),(e=>r(e))),{setProgress:r}}(n.$linearProgress,t);o(t.progress),e.dataset.buffer&&s(t.buffer)})),(t,n)=>((0,d.openBlock)(),(0,d.createBlock)(x,{ref_key:"linearProgress",ref:r,class:(0,d.normalizeClass)(o.value),"aria-label":t.label,"aria-valuemin":"0","aria-valuemax":"1","data-buffer":!!e.buffer},null,8,["class","aria-label","data-buffer"]))}}));return o=o.default}()}));