UNPKG

sinter-compositions

Version:
2 lines (1 loc) 7.21 kB
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).SinterCompositions={},n.Vue)}(this,(function(n,e){"use strict";function t(){}var r=function(){function n(){this.eventData=new Map}return n.prototype.on=function(n,e,t){if(void 0===t&&(t=!1),!this.include(n,e)){var r=this.eventData.has(n)?this.eventData.get(n):[];r.push({once:t,handler:e}),this.eventData.set(n,r)}},n.prototype.once=function(n,e){this.on(n,e,!0)},n.prototype.emit=function(n){for(var e=[],t=1;t<arguments.length;t++)e[t-1]=arguments[t];var r=this.eventData.get(n);r&&(r.forEach((function(n){try{n.handler.apply(null,e)}catch(n){console.error("[EventEmitter]: handler 执行异常",n)}})),r=r.filter((function(n){return!n.once})),this.eventData.set(n,r))},n.prototype.include=function(n,e){var t=this.eventData.get(n);return!!t&&-1!==t.findIndex((function(n){return n.handler===e}))},n.prototype.off=function(n,e){if(this.include(n,e)){var t=this.eventData.get(n).filter((function(n){return n.handler!==e}));this.eventData.set(n,t)}},n}(),o=new Map;var i={key:"id",children:"children"};function u(n,e){var t=window.URL.createObjectURL(new Blob([n],{type:"application/vnd.ms-excel;charset=utf-8"})),r=document.createElement("a");r.style.display="none",r.href=t;var o=new Date,i=e||o.getFullYear()+"-"+(o.getMonth()+1)+"-"+o.getDate();r.setAttribute("download",i+".xlsx"),document.body.appendChild(r),r.click(),document.body.removeChild(r),window.URL.revokeObjectURL(t)}function c(n){var e=document.createElement("a");e.style.display="none",e.href=n,document.body.appendChild(e),e.click(),URL.revokeObjectURL(e.href),document.body.removeChild(e)}n.useBackupData=function(n){function t(n){return JSON.parse(JSON.stringify(n))}var r=t(n),o=e.ref(n);return[o,function(){o.value=t(r)}]},n.useCommands=function(n,t){void 0===n&&(n=[]);var r=void 0===t?{}:t,o=r.defaultIndex,i=void 0===o?-1:o,u=r.onInitState,c=void 0===u?null:u,a=r.onChange,l=void 0===a?null:a,d=e.reactive({commands:n,currentIndex:i});c&&c(d);var f=e.computed((function(){return-1===d.currentIndex||d.currentIndex>=d.commands.length?null:d.commands[d.currentIndex]})),v=e.computed((function(){return 0===d.currentIndex})),s=e.computed((function(){return d.currentIndex===d.commands.length-1}));return e.watch((function(){return d.currentIndex}),(function(n){return n<0?d.currentIndex=0:n>=d.commands.length?d.currentIndex=d.commands.length-1:void(l&&l(n))})),[d,{currentCommand:f,isHeader:v,isFooter:s,swapIndex:function(n,e){if(void 0===e&&(e=d.currentIndex),!(n<0||e<0||n>=d.commands.length||e>=d.commands.length)){var t=d.commands[n];d.commands[n]=d.commands[e],d.commands[e]=t}},activeIndex:function(n){d.currentIndex=n},activeCommand:function(n){var e=-1;-1!==(e="string"==typeof n?d.commands.findIndex((function(e){return e.command===n})):d.commands.findIndex((function(e){return e.command===n.command})))&&(d.currentIndex=e)}}]},n.useCountDown=function(n,r,o){var i=void 0===o?{}:o,u=i.step,c=void 0===u?1e3:u,a=i.done,l=void 0===a?t:a,d=i.immediate,f=void 0!==d&&d,v=e.ref(n),s=null;function p(){return setTimeout((function(){v.value-=c,v.value<=0?(null!==s&&clearTimeout(s),l&&l.call(null)):(r&&r(v.value,c),s=p())}),c)}var m={run:function(){s=p()},toSecond:e.computed((function(){return v.value/1e3}))};return f&&m.run(),[v,m]},n.useCreateExporter=function(){return{exportFile:u,exportPath:c}},n.useEventEmitter=function(n){var t=function(n){if(n){var e=o.get(n);if(e)return e;var t=new r;return o.set(n,t),t}return new r}(n.scopeKey);return(null==n?void 0:n.providerKey)&&e.provide(n.providerKey,t),t},n.useNumberScope=function(n,t,r){var o=void 0===r?{}:r,i=o.loop,u=void 0!==i&&i,c=o.step,a=void 0===c?1:c,l=o.onChange,d=void 0===l?null:l,f=o.onInitState,v=void 0===f?null:f,s=e.reactive({current:n,min:n,max:t});v&&v(s);var p=e.computed((function(){return s.current===s.min})),m=e.computed((function(){return s.current===s.max}));return e.watch((function(){return s.current}),(function(n){s.current=function(n,e,t,r){return void 0===n&&(n=!1),n?e>r?t:e<t?r:e:e>r?r:e<t?t:e}(u,n,s.min,s.max),n!==s.current&&d&&d(s.current,n)})),[s,{next:function(){s.current+=a},prev:function(){s.current-=a},isMin:p,isMax:m}]},n.useOnce=function(n){var e=!1;return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];e||(n.apply(t),e=!0)}},n.useScroll=function(n,t){var r=void 0===t?{}:t,o=r.observer,i=void 0!==o&&o,u=r.immediate,c=void 0!==u&&u,a={top:0,left:0,direction:"none"},l=i?e.reactive(a):a,d=e.computed((function(){return"vertical"===l.direction})),f=e.computed((function(){return"horizontal"===l.direction})),v=null,s=null,p=null;function m(){var e,t,r,o,i,u=(e=l.top,t=l.left,r=e,o=t,function(n,e,t){return n!==r?(r=n,o=e,"vertical"):e!==o?(r=n,o=e,"horizontal"):t});if(s=("string"==typeof(i=n)?document.querySelector(i):i instanceof HTMLElement?i:i.value)||null,console.log(s),null===s)return console.warn("[useScroll]:找不到 scroll 容器");null!==(v=function(n){var e=n.target;l.top=e.scrollTop,l.left=e.scrollLeft,l.direction=u(l.top,l.left,l.direction),p&&p(l,n)})&&s.addEventListener("scroll",v)}return e.onMounted((function(){c&&m()})),[l,{start:m,stop:function(){s&&v&&s.removeEventListener("scroll",v)},isVertical:d,isHorizontal:f,defineScroll:function(n){p=n}}]},n.useStack=function(n,t){void 0===n&&(n=[]);var r=(void 0===t?{}:t).observer,o=void 0!==r&&r?e.reactive(n):n;return[o,{push:function(n){o.push(n)},pop:function(){if(0===o.length)return null;var n=o.pop();return n||null}}]},n.useToggle=function(n,t){var r=e.reactive({value:!!n});return[r,function(){if(r.value=!r.value,t)return t(r.value)}]},n.useTree=function(n,t){var r=(void 0===n?{}:n).props,o=void 0===r?i:r,u=e.ref([]);function c(n){var e=function(t,r){for(var i=r.level,u=r.parentIndex,c=r.parent,a=0;a<t.length;a++){var l=t[a],d=l[o.children]&&Array.isArray(l[o.children])&&l[o.children].length>0,f=n(t[a],{level:i,parentIndex:u,hasChildren:d,parent:c,index:a});return void 0===f&&d?e(l[o.children],{level:i+1,parentIndex:a,parent:l}):f}};return e(u.value,{level:1,parentIndex:-1,parent:null})}function a(n){var e=null;return c((function(t){if(t[o.key]===n)return e=t})),e}var l={each:c,find:a,remove:function(n){c((function(e,t){var r=t.level,i=t.parent,c=t.index;if(e[o.key]===n)return 1===r?u.value.splice(u.value.find((function(e){return e[o.key]===n})),1):i[o.children].splice(c,1),e}))},append:function(n,e){var t=a(n);null!==t&&(t[o.children]&&Array.isArray(t[o.children])||(t[o.children]=[]),t.push(e))},set:function(n){u.value=n}};return[u,l]},n.useWrapperFetch=function(n,t){void 0===t&&(t={immediate:!0,lock:!0});var r=e.reactive({loaded:!1,loading:!1,success:!1});return[r,function(){for(var e=[],o=0;o<arguments.length;o++)e[o]=arguments[o];if(!t.lock||!r.loading){r.loading=!0;var i=n.apply(null,e);return(i instanceof Promise||"function"==typeof i.then&&"function"==typeof i.finally&&"function"==typeof i.catch)&&i.then((function(){r.success=!0})).catch((function(){return r.success=!1})).finally((function(){r.loaded=!0,r.loading=!1})),i}}]},Object.defineProperty(n,"__esModule",{value:!0})}));