@volverjs/ui-vue
Version:
@volverjs/ui-vue is a lightweight Vue 3 component library to accompany @volverjs/style.
2 lines (1 loc) • 10.7 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("vue"),require("comlink"),require("pica")):"function"==typeof define&&define.amd?define(["exports","vue","comlink","pica"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).composables={},t.vue,t.comlink,t.Pica)}(this,function(t,e,n,r){"use strict";const a="default",o="information",s=new Map([["success","check-circle"],["info",o],["warning","warning"],["danger","error"]]),i=e.reactive(new Map([[a,new Map]]));function l(t){const n=e.ref(0),r=e.ref(0),a=e.ref();let o=0,s=0,i=0,l=0;const c=t=>{const e=t.target;o=e.scrollLeft-l,s=e.scrollTop-i,r.value=r.value-s,n.value=n.value-o,l=e.scrollLeft,i=e.scrollTop},u=()=>({width:0,height:0,x:n.value,y:r.value,top:r.value,left:n.value,right:n.value,bottom:r.value});return e.getCurrentInstance()&&(e.onMounted(()=>{t.value&&(t.value.init({getBoundingClientRect:u}),a.value=function(t){if(!t)return;let e=t.parentElement;for(;e;){const{overflow:t}=window.getComputedStyle(e);if(t.split(" ").every(t=>"auto"===t||"scroll"===t))return e;e=e.parentElement}return document.documentElement}(t.value.$el),a.value&&a.value.addEventListener("scroll",c))}),e.onUnmounted(()=>{a.value&&a.value.removeEventListener("scroll",c)})),{x:n,y:r,getBoundingClientRect:u,onScroll:c}}const c='!function(){"use strict";var t=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","#","$","%","*","+",",","-",".",":",";","=","?","@","[","]","^","_","{","|","}","~"],e=e=>{let n=0;for(let r=0;r<e.length;r++){let a=e[r];n=83*n+t.indexOf(a)}return n},n=(e,n)=>{var r="";for(let a=1;a<=n;a++){let o=Math.floor(e)/Math.pow(83,n-a)%83;r+=t[Math.floor(o)]}return r},r=t=>{let e=t/255;return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)},a=t=>{let e=Math.max(0,Math.min(1,t));return e<=.0031308?Math.trunc(12.92*e*255+.5):Math.trunc(255*(1.055*Math.pow(e,.4166666666666667)-.055)+.5)},o=(t,e)=>(t=>t<0?-1:1)(t)*Math.pow(Math.abs(t),e),s=class extends Error{constructor(t){super(t),this.name="ValidationError",this.message=t}},i=t=>{if(!t||t.length<6)throw new s("The blurhash string must be at least 6 characters");let n=e(t[0]),r=Math.floor(n/9)+1,a=n%9+1;if(t.length!==4+2*a*r)throw new s(`blurhash length mismatch: length is ${t.length} but it should be ${4+2*a*r}`)},l=t=>{let e=t>>8&255,n=255&t;return[r(t>>16),r(e),r(n)]},c=(t,e)=>{let n=Math.floor(t/361),r=Math.floor(t/19)%19,a=t%19;return[o((n-9)/9,2)*e,o((r-9)/9,2)*e,o((a-9)/9,2)*e]},h=(t,n,r,o)=>{i(t),o|=1;let s=e(t[0]),h=Math.floor(s/9)+1,u=s%9+1,f=(e(t[1])+1)/166,p=new Array(u*h);for(let a=0;a<p.length;a++)if(0===a){let n=e(t.substring(2,6));p[a]=l(n)}else{let n=e(t.substring(4+2*a,6+2*a));p[a]=c(n,f*o)}let m=4*n,g=new Uint8ClampedArray(m*r);for(let e=0;e<r;e++)for(let t=0;t<n;t++){let o=0,s=0,i=0;for(let a=0;a<h;a++)for(let l=0;l<u;l++){let c=Math.cos(Math.PI*t*l/n)*Math.cos(Math.PI*e*a/r),h=p[l+a*u];o+=h[0]*c,s+=h[1]*c,i+=h[2]*c}let l=a(o),c=a(s),f=a(i);g[4*t+0+e*m]=l,g[4*t+1+e*m]=c,g[4*t+2+e*m]=f,g[4*t+3+e*m]=255}return g},u=(t,e,n,a)=>{let o=0,s=0,i=0,l=4*e;for(let h=0;h<e;h++){let e=4*h;for(let c=0;c<n;c++){let n=e+c*l,u=a(h,c);o+=u*r(t[n]),s+=u*r(t[n+1]),i+=u*r(t[n+2])}}let c=1/(e*n);return[o*c,s*c,i*c]},f=(t,e,r,i,l)=>{if(i<1||i>9||l<1||l>9)throw new s("BlurHash must have between 1 and 9 components");if(e*r*4!==t.length)throw new s("Width and height must match the pixels array");let c=[];for(let n=0;n<l;n++)for(let a=0;a<i;a++){let o=0==a&&0==n?1:2,s=u(t,e,r,(t,s)=>o*Math.cos(Math.PI*a*t/e)*Math.cos(Math.PI*n*s/r));c.push(s)}let h,f=c[0],p=c.slice(1),m="";if(m+=n(i-1+9*(l-1),1),p.length>0){let t=Math.max(...p.map(t=>Math.max(...t))),e=Math.floor(Math.max(0,Math.min(82,Math.floor(166*t-.5))));h=(e+1)/166,m+=n(e,1)}else h=1,m+=n(0,1);return m+=n((t=>(a(t[0])<<16)+(a(t[1])<<8)+a(t[2]))(f),4),p.forEach(t=>{m+=n(((t,e)=>19*Math.floor(Math.max(0,Math.min(18,Math.floor(9*o(t[0]/e,.5)+9.5))))*19+19*Math.floor(Math.max(0,Math.min(18,Math.floor(9*o(t[1]/e,.5)+9.5))))+Math.floor(Math.max(0,Math.min(18,Math.floor(9*o(t[2]/e,.5)+9.5)))))(t,h),2)}),m};const p=Symbol("Comlink.proxy"),m=Symbol("Comlink.endpoint"),g=Symbol("Comlink.releaseProxy"),M=Symbol("Comlink.finalizer"),d=Symbol("Comlink.thrown"),y=t=>"object"==typeof t&&null!==t||"function"==typeof t,w=new Map([["proxy",{canHandle:t=>y(t)&&t[p],serialize(t){const{port1:e,port2:n}=new MessageChannel;return b(t,e),[n,[n]]},deserialize:t=>(t.start(),function(t,e){const n=new Map;return t.addEventListener("message",function(t){const{data:e}=t;if(!e||!e.id)return;const r=n.get(e.id);if(r)try{r(e)}finally{n.delete(e.id)}}),P(t,n,[],e)}(t))}],["throw",{canHandle:t=>y(t)&&d in t,serialize({value:t}){let e;return e=t instanceof Error?{isError:!0,value:{message:t.message,name:t.name,stack:t.stack}}:{isError:!1,value:t},[e,[]]},deserialize(t){if(t.isError)throw Object.assign(new Error(t.value.message),t.value);throw t.value}}]]);function b(t,e=globalThis,n=["*"]){e.addEventListener("message",function r(a){if(!a||!a.data)return;if(!function(t,e){for(const n of t){if(e===n||"*"===n)return!0;if(n instanceof RegExp&&n.test(e))return!0}return!1}(n,a.origin))return void console.warn(`Invalid origin \'${a.origin}\' for comlink proxy`);const{id:o,type:s,path:i}=Object.assign({path:[]},a.data),l=(a.data.argumentList||[]).map(L);let c;try{const e=i.slice(0,-1).reduce((t,e)=>t[e],t),n=i.reduce((t,e)=>t[e],t);switch(s){case"GET":c=n;break;case"SET":e[i.slice(-1)[0]]=L(a.data.value),c=!0;break;case"APPLY":c=n.apply(e,l);break;case"CONSTRUCT":c=function(t){return Object.assign(t,{[p]:!0})}(new n(...l));break;case"ENDPOINT":{const{port1:e,port2:n}=new MessageChannel;b(t,n),c=function(t,e){return T.set(t,e),t}(e,[e])}break;case"RELEASE":c=void 0;break;default:return}}catch(h){c={value:h,[d]:0}}Promise.resolve(c).catch(t=>({value:t,[d]:0})).then(n=>{const[a,i]=R(n);e.postMessage(Object.assign(Object.assign({},a),{id:o}),i),"RELEASE"===s&&(e.removeEventListener("message",r),E(e),M in t&&"function"==typeof t[M]&&t[M]())}).catch(t=>{const[n,r]=R({value:new TypeError("Unserializable return value"),[d]:0});e.postMessage(Object.assign(Object.assign({},n),{id:o}),r)})}),e.start&&e.start()}function E(t){(function(t){return"MessagePort"===t.constructor.name})(t)&&t.close()}function v(t){if(t)throw new Error("Proxy has been released and is not useable")}function S(t){return O(t,new Map,{type:"RELEASE"}).then(()=>{E(t)})}const x=new WeakMap,k="FinalizationRegistry"in globalThis&&new FinalizationRegistry(t=>{const e=(x.get(t)||0)-1;x.set(t,e),0===e&&S(t)});function P(t,e,n=[],r=function(){}){let a=!1;const o=new Proxy(r,{get(r,s){if(v(a),s===g)return()=>{!function(t){k&&k.unregister(t)}(o),S(t),e.clear(),a=!0};if("then"===s){if(0===n.length)return{then:()=>o};const r=O(t,e,{type:"GET",path:n.map(t=>t.toString())}).then(L);return r.then.bind(r)}return P(t,e,[...n,s])},set(r,o,s){v(a);const[i,l]=R(s);return O(t,e,{type:"SET",path:[...n,o].map(t=>t.toString()),value:i},l).then(L)},apply(r,o,s){v(a);const i=n[n.length-1];if(i===m)return O(t,e,{type:"ENDPOINT"}).then(L);if("bind"===i)return P(t,e,n.slice(0,-1));const[l,c]=A(s);return O(t,e,{type:"APPLY",path:n.map(t=>t.toString()),argumentList:l},c).then(L)},construct(r,o){v(a);const[s,i]=A(o);return O(t,e,{type:"CONSTRUCT",path:n.map(t=>t.toString()),argumentList:s},i).then(L)}});return function(t,e){const n=(x.get(e)||0)+1;x.set(e,n),k&&k.register(t,e,t)}(o,t),o}function A(t){const e=t.map(R);return[e.map(t=>t[0]),(n=e.map(t=>t[1]),Array.prototype.concat.apply([],n))];var n}const T=new WeakMap;function R(t){for(const[e,n]of w)if(n.canHandle(t)){const[r,a]=n.serialize(t);return[{type:"HANDLER",name:e,value:r},a]}return[{type:"RAW",value:t},T.get(t)||[]]}function L(t){switch(t.type){case"HANDLER":return w.get(t.name).deserialize(t.value);case"RAW":return t.value}}function O(t,e,n,r){return new Promise(a=>{const o=new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-");e.set(o,a),t.start&&t.start(),t.postMessage(Object.assign({id:o},n),r)})}b({ValidationError:s,encode:f,decode:h,isBlurhashValid:t=>{try{i(t)}catch(e){return{result:!1,errorReason:e.message}}return{result:!0}}})}();\n',u="undefined"!=typeof self&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",c],{type:"text/javascript;charset=utf-8"});const h=n.wrap(new function(t){let e;try{if(e=u&&(self.URL||self.webkitURL).createObjectURL(u),!e)throw"";const n=new Worker(e,{name:t?.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),n}catch(n){return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(c),{name:t?.name})}});function f(t){return new Promise((e,n)=>{const r=new Image;r.onload=()=>e(r),r.onerror=(...t)=>n(t),r.src=t})}t.useAlert=function(){const t=(t=a)=>e.computed(()=>{const e=i.get(t);return e&&e instanceof Map?Array.from(e?.values()).sort((t,e)=>t.timestamp-e.timestamp):[]});return{groups:i,alerts:t(),addAlert:({id:t=crypto.randomUUID(),group:e=a,title:n,icon:r=o,content:l,footer:c,modifiers:u="info",dismissable:h=true,autoClose:f=1e4,timestamp:m=Date.now()}={})=>{i.has(e)||i.set(e,new Map);const d=i.get(e),p="string"==typeof u?u.split(" "):u;if(!r){const t=p.find(t=>s.has(t));t&&(r=s.get(t))}d?.set(t.toString(),{id:t,group:e,title:n,icon:r,content:l,footer:c,modifiers:u,dismissable:h,autoClose:f,timestamp:m})},removeAlert:(t,e=a)=>{const n=i.get(e);n?.delete(t.toString())},getAlerts:t}},t.useBlurhash=function(){return{encode:async function(t){const e=URL.createObjectURL(t),n=await f(e);if("width"in n&&"height"in n){const{width:t,height:e}=(a=n.width,o=n.height,s=32,a>o?{width:s,height:Math.round(s*(o/a))}:{width:Math.round(s*(a/o)),height:s}),i=await async function(t,e,n){const a=new r,o=document.createElement("canvas");o.width=e,o.height=n;const s=await a.resize(t,o);return s.getContext("2d")?.getImageData(0,0,e,n).data}(n,t,e);if(i)return h.encode(i,t,e,4,4)}var a,o,s},decode:h.decode,loadImage:f}},t.useDropdownContextmenu=function(t,n){const{x:r,y:a,getBoundingClientRect:o,onScroll:s}=l(t),i=e=>{r.value=e.clientX,a.value=e.clientY,e.preventDefault(),t.value.show()},c=e.computed(()=>e.unref(n));return c&&e.getCurrentInstance()&&(e.onMounted(()=>{c.value?.addEventListener("contextmenu",i,!1)}),e.onUnmounted(()=>{c.value?.removeEventListener("contextmenu",i)})),{x:r,y:a,getBoundingClientRect:o,onContextmenu:i,onScroll:s}},t.useDropdownVirtualElement=l,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});