@atoms-studio/composables
Advanced tools
Comparing version
@@ -1,57 +0,7 @@ | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
} | ||
return a; | ||
}; | ||
import { computed, inject } from "vue"; | ||
const useURL = (to, base) => { | ||
if (!base) { | ||
throw new Error("Base is required"); | ||
} | ||
const isDummy = computed(() => to.value === "#"); | ||
const url = computed(() => { | ||
if (typeof to.value === "string") { | ||
return new URL(to.value, base); | ||
} | ||
return null; | ||
}); | ||
const origin = computed(() => { | ||
var _a; | ||
return ((_a = url.value) == null ? void 0 : _a.origin) || ""; | ||
}); | ||
const path = computed(() => { | ||
var _a; | ||
return isDummy.value ? "#" : ((_a = url.value) == null ? void 0 : _a.pathname) || ""; | ||
}); | ||
const isExternal = computed(() => { | ||
return isDummy.value || url.value !== null && origin.value !== base; | ||
}); | ||
return { | ||
url, | ||
origin, | ||
path, | ||
isExternal, | ||
isDummy | ||
}; | ||
}; | ||
import { inject, computed } from "vue"; | ||
/*! | ||
* vue-router v4.0.15 | ||
* vue-router v4.1.6 | ||
* (c) 2022 Eduardo San Martin Morote | ||
* @license MIT | ||
*/ | ||
const hasSymbol = typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol"; | ||
const PolySymbol = (name) => hasSymbol ? Symbol(name) : "_vr_" + name; | ||
const routerKey = /* @__PURE__ */ PolySymbol("r"); | ||
const routeLocationKey = /* @__PURE__ */ PolySymbol("rl"); | ||
var NavigationType; | ||
@@ -74,2 +24,4 @@ (function(NavigationType2) { | ||
})(NavigationFailureType || (NavigationFailureType = {})); | ||
const routerKey = Symbol(""); | ||
const routeLocationKey = Symbol(""); | ||
function useRouter() { | ||
@@ -107,3 +59,3 @@ return inject(routerKey); | ||
const updateState = (partialState) => { | ||
const newState = __spreadValues(__spreadValues({}, state.value), partialState); | ||
const newState = { ...state.value, ...partialState }; | ||
const newQuery = {}; | ||
@@ -115,3 +67,3 @@ for (const stateKey of stateKeys) { | ||
} | ||
return router[method]({ query: __spreadValues(__spreadValues({}, route.query), newQuery) }); | ||
return router[method]({ query: { ...route.query, ...newQuery } }); | ||
}; | ||
@@ -123,2 +75,32 @@ return { | ||
}; | ||
const useURL = (to, base) => { | ||
if (!base) { | ||
throw new Error("Base is required"); | ||
} | ||
const isDummy = computed(() => to.value === "#"); | ||
const url = computed(() => { | ||
if (typeof to.value === "string") { | ||
return new URL(to.value, base); | ||
} | ||
return null; | ||
}); | ||
const origin = computed(() => { | ||
var _a; | ||
return ((_a = url.value) == null ? void 0 : _a.origin) || ""; | ||
}); | ||
const path = computed(() => { | ||
var _a; | ||
return isDummy.value ? "#" : ((_a = url.value) == null ? void 0 : _a.pathname) || ""; | ||
}); | ||
const isExternal = computed(() => { | ||
return isDummy.value || url.value !== null && origin.value !== base; | ||
}); | ||
return { | ||
url, | ||
origin, | ||
path, | ||
isExternal, | ||
isDummy | ||
}; | ||
}; | ||
const getFileExtension = (url) => { | ||
@@ -158,3 +140,4 @@ var _a, _b, _c; | ||
const isDatoAsset = (url) => url && url.includes("datocms-assets"); | ||
const usePicture = (image, format, legacyFormat, mode, quality, sizesProp, screensProp, datoFocalPoint, datoAutoFormat) => { | ||
const isStoryblokAsset = (url) => url && url.includes("a.storyblok"); | ||
const usePicture = (image, format, legacyFormat, mode, quality, sizesProp, screensProp, datoFocalPoint, datoAutoFormat, sbFocalPoint) => { | ||
const imageUrl = computed(() => { | ||
@@ -217,3 +200,3 @@ return "url" in image ? image.url : "file" in image ? image.file.url : ""; | ||
}); | ||
const createCfUrlImage = (breakPoint, url, format2 = "jpg", height) => { | ||
const createUrlImage = (breakPoint, url, format2 = "jpg", height) => { | ||
let resizeParams = ""; | ||
@@ -235,2 +218,9 @@ if (isCtfAsset(url)) { | ||
} | ||
if (isStoryblokAsset(url)) { | ||
resizeParams = "/m/"; | ||
resizeParams += breakPoint && height ? `${breakPoint}x${height}/` : breakPoint ? `${breakPoint}x0/` : ""; | ||
resizeParams += "filters:"; | ||
resizeParams += sbFocalPoint ? `focal(${sbFocalPoint}):` : ""; | ||
resizeParams += `quality(${quality})`; | ||
} | ||
return `${url}${resizeParams}`; | ||
@@ -278,3 +268,3 @@ }; | ||
media: `(max-width: ${screenMaxWidth}px)`, | ||
src: `${createCfUrlImage(_cWidth, imageUrl.value, format2, _cHeight)}` | ||
src: `${createUrlImage(_cWidth, imageUrl.value, format2, _cHeight)}` | ||
}); | ||
@@ -281,0 +271,0 @@ } |
@@ -1,5 +0,5 @@ | ||
(function(r,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(r=typeof globalThis!="undefined"?globalThis:r||self,e(r.MyLib={},r.Vue))})(this,function(r,e){"use strict";var nt=Object.defineProperty;var V=Object.getOwnPropertySymbols;var st=Object.prototype.hasOwnProperty,ot=Object.prototype.propertyIsEnumerable;var E=(r,e,a)=>e in r?nt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):r[e]=a,W=(r,e)=>{for(var a in e||(e={}))st.call(e,a)&&E(r,a,e[a]);if(V)for(var a of V(e))ot.call(e,a)&&E(r,a,e[a]);return r};const a=(t,o)=>{if(!o)throw new Error("Base is required");const n=e.computed(()=>t.value==="#"),c=e.computed(()=>typeof t.value=="string"?new URL(t.value,o):null),u=e.computed(()=>{var h;return((h=c.value)==null?void 0:h.origin)||""}),m=e.computed(()=>{var h;return n.value?"#":((h=c.value)==null?void 0:h.pathname)||""}),y=e.computed(()=>n.value||c.value!==null&&u.value!==o);return{url:c,origin:u,path:m,isExternal:y,isDummy:n}};/*! | ||
* vue-router v4.0.15 | ||
(function(p,n){typeof exports=="object"&&typeof module!="undefined"?n(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],n):(p=typeof globalThis!="undefined"?globalThis:p||self,n(p.MyLib={},p.Vue))})(this,function(p,n){"use strict";/*! | ||
* vue-router v4.1.6 | ||
* (c) 2022 Eduardo San Martin Morote | ||
* @license MIT | ||
*/const K=typeof Symbol=="function"&&typeof Symbol.toStringTag=="symbol",I=t=>K?Symbol(t):"_vr_"+t,C=I("r"),H=I("rl");var U;(function(t){t.pop="pop",t.push="push"})(U||(U={}));var k;(function(t){t.back="back",t.forward="forward",t.unknown=""})(k||(k={}));var A;(function(t){t[t.aborted=4]="aborted",t[t.cancelled=8]="cancelled",t[t.duplicated=16]="duplicated"})(A||(A={}));function B(){return e.inject(C)}function F(){return e.inject(H)}const O=(t,o="replace")=>{const n=F(),c=B();let u;Array.isArray(t)?u=t.reduce(($,f)=>($[f]={get:d=>d,set:d=>d},$),{}):u=t;const m=Object.keys(u),y=e.computed(()=>{const $={};for(const f of m){const d=n.query[f],b=u[f].get(d);$[f]=b}return $});return{state:y,updateState:$=>{const f=W(W({},y.value),$),d={};for(const b of m){const S=f[b],z=u[b].set(S);d[b]=z}return c[o]({query:W(W({},n.query),d)})}}},Q=t=>{var n,c,u;return(u=(c=(n=t.split(/[?#]/).shift())==null?void 0:n.split("/").pop())==null?void 0:c.split(".").pop())!=null?u:"jpg"},T=(t,o=0,n=0)=>{if(o>t||n>t){const c=o/n;Math.max(o,n)===o?(o=t,n=Math.round(o/c)):(n=t,o=Math.round(n*c))}return{width:o,height:n}},P=(t="")=>{if(typeof t=="number")return t;if(typeof t=="string"&&t.replace("px","").match(/^\d+$/g))return parseInt(t,10)},X=t=>t&&t.includes("ctfassets"),Y=t=>t&&t.includes("datocms-assets"),G=(t,o,n,c,u,m,y,h,$)=>{const f=e.computed(()=>"url"in t?t.url:"file"in t?t.file.url:""),d=e.computed(()=>"width"in t?t.width:t&&"file"in t?t.file.details.image.width:0),b=e.computed(()=>t&&"height"in t?t.height:t&&"file"in t?t.file.details.image.height:0),S=e.computed(()=>Q(f.value)),z=e.computed(()=>["png","webp","gif"].includes(S.value)),j=e.computed(()=>o||(S.value==="svg"?"svg":"webp")),L=e.computed(()=>n||{webp:z.value?"png":"jpeg",svg:"png"}[j.value]||S.value),_=e.computed(()=>T(4e3,d.value,b.value)),Z=e.computed(()=>j.value==="svg"?[{srcset:f.value}]:(L.value!==j.value?[L.value,j.value]:[j.value]).map(l=>{const{srcset:g,sizes:s,src:M}=tt(l);return{src:M,type:`image/${l}`,sizes:s,srcset:g}})),N=(x,v,l="jpg",g)=>{let s="";return X(v)&&(s="?",s+=`w=${x}&`,s+=g?`h=${g}&`:"",s+=c?`fit=${c}&`:"",s+=`q=${u}&fm=${l&&l==="jpeg"?"jpg":l}`),Y(v)&&(s="?",s+=`crop=focalpoint&fit=crop&fp-x=${h.x}&fp-y=${h.y}&`,s+=`w=${x}&`,s+=g?`h=${g}&`:"",s+=$?"auto=format&":"",s+=`q=${u}&fm=${l&&l==="jpeg"?"jpg":l}`),`${v}${s}`},tt=x=>{const v=P(_.value.width),l=P(_.value.height),g=v&&l?l/v:0,s=[],M={};if(typeof m=="string")for(const i of m.split(/[\s,]+/).filter(p=>p)){const p=i.split(":");p.length===2&&(M[p[0].trim()]=p[1].trim())}else Object.assign(M,m);for(const i in M){const p=y&&y[i]||parseInt(i);let w=String(M[i]);const D=w.endsWith("vw");if(!D&&/^\d+$/.test(w)&&(w=w+"px"),!D&&!w.endsWith("px"))continue;let q=parseInt(w);if(!p||!q)continue;D&&(q=Math.round(q/100*p));const et=g?Math.round(q*g):l;s.push({width:q,size:w,screenMaxWidth:p,media:`(max-width: ${p}px)`,src:`${N(q,f.value,x,et)}`})}s.sort((i,p)=>i.screenMaxWidth-p.screenMaxWidth);const R=s[s.length-1];return R&&(R.media=""),{sizes:s.map(i=>`${i.media?i.media+" ":""}${i.size}`).join(", "),srcset:s.map(i=>`${i.src} ${i.width}w`).join(", "),src:R==null?void 0:R.src}};return{imageUrl:f,imageWidth:d,imageHeight:b,originalFormat:S,isTransparent:z,nFormat:j,nLegacyFormat:L,safeDimensions:_,nSources:Z}},J=(t,o,n,c)=>({focalPoint:e.computed(()=>{const m=t*100/n,y=o*100/c;return{"object-position":`${m}% ${y}%`}})});r.useFocalPoint=J,r.usePicture=G,r.useRouteState=O,r.useURL=a,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
*/var A;(function(t){t.pop="pop",t.push="push"})(A||(A={}));var D;(function(t){t.back="back",t.forward="forward",t.unknown=""})(D||(D={}));var I;(function(t){t[t.aborted=4]="aborted",t[t.cancelled=8]="cancelled",t[t.duplicated=16]="duplicated"})(I||(I={}));const _=Symbol(""),E=Symbol("");function K(){return n.inject(_)}function k(){return n.inject(E)}const H=(t,o="replace")=>{const s=k(),r=K();let c;Array.isArray(t)?c=t.reduce((h,m)=>(h[m]={get:i=>i,set:i=>i},h),{}):c=t;const d=Object.keys(c),y=n.computed(()=>{const h={};for(const m of d){const i=s.query[m],w=c[m].get(i);h[m]=w}return h});return{state:y,updateState:h=>{const m={...y.value,...h},i={};for(const w of d){const R=m[w],S=c[w].set(R);i[w]=S}return r[o]({query:{...s.query,...i}})}}},B=(t,o)=>{if(!o)throw new Error("Base is required");const s=n.computed(()=>t.value==="#"),r=n.computed(()=>typeof t.value=="string"?new URL(t.value,o):null),c=n.computed(()=>{var g;return((g=r.value)==null?void 0:g.origin)||""}),d=n.computed(()=>{var g;return s.value?"#":((g=r.value)==null?void 0:g.pathname)||""}),y=n.computed(()=>s.value||r.value!==null&&c.value!==o);return{url:r,origin:c,path:d,isExternal:y,isDummy:s}},C=t=>{var s,r,c;return(c=(r=(s=t.split(/[?#]/).shift())==null?void 0:s.split("/").pop())==null?void 0:r.split(".").pop())!=null?c:"jpg"},O=(t,o=0,s=0)=>{if(o>t||s>t){const r=o/s;Math.max(o,s)===o?(o=t,s=Math.round(o/r)):(s=t,o=Math.round(s*r))}return{width:o,height:s}},U=(t="")=>{if(typeof t=="number")return t;if(typeof t=="string"&&t.replace("px","").match(/^\d+$/g))return parseInt(t,10)},Q=t=>t&&t.includes("ctfassets"),X=t=>t&&t.includes("datocms-assets"),Y=t=>t&&t.includes("a.storyblok"),F=(t,o,s,r,c,d,y,g,h,m)=>{const i=n.computed(()=>"url"in t?t.url:"file"in t?t.file.url:""),w=n.computed(()=>"width"in t?t.width:t&&"file"in t?t.file.details.image.width:0),R=n.computed(()=>t&&"height"in t?t.height:t&&"file"in t?t.file.details.image.height:0),S=n.computed(()=>C(i.value)),V=n.computed(()=>["png","webp","gif"].includes(S.value)),x=n.computed(()=>o||(S.value==="svg"?"svg":"webp")),W=n.computed(()=>s||{webp:V.value?"png":"jpeg",svg:"png"}[x.value]||S.value),z=n.computed(()=>O(4e3,w.value,R.value)),J=n.computed(()=>x.value==="svg"?[{srcset:i.value}]:(W.value!==x.value?[W.value,x.value]:[x.value]).map(l=>{const{srcset:f,sizes:e,src:b}=Z(l);return{src:b,type:`image/${l}`,sizes:e,srcset:f}})),T=($,j,l="jpg",f)=>{let e="";return Q(j)&&(e="?",e+=`w=${$}&`,e+=f?`h=${f}&`:"",e+=r?`fit=${r}&`:"",e+=`q=${c}&fm=${l&&l==="jpeg"?"jpg":l}`),X(j)&&(e="?",e+=`crop=focalpoint&fit=crop&fp-x=${g.x}&fp-y=${g.y}&`,e+=`w=${$}&`,e+=f?`h=${f}&`:"",e+=h?"auto=format&":"",e+=`q=${c}&fm=${l&&l==="jpeg"?"jpg":l}`),Y(j)&&(e="/m/",e+=$&&f?`${$}x${f}/`:$?`${$}x0/`:"",e+="filters:",e+=m?`focal(${m}):`:"",e+=`quality(${c})`),`${j}${e}`},Z=$=>{const j=U(z.value.width),l=U(z.value.height),f=j&&l?l/j:0,e=[],b={};if(typeof d=="string")for(const u of d.split(/[\s,]+/).filter(a=>a)){const a=u.split(":");a.length===2&&(b[a[0].trim()]=a[1].trim())}else Object.assign(b,d);for(const u in b){const a=y&&y[u]||parseInt(u);let v=String(b[u]);const L=v.endsWith("vw");if(!L&&/^\d+$/.test(v)&&(v=v+"px"),!L&&!v.endsWith("px"))continue;let M=parseInt(v);if(!a||!M)continue;L&&(M=Math.round(M/100*a));const P=f?Math.round(M*f):l;e.push({width:M,size:v,screenMaxWidth:a,media:`(max-width: ${a}px)`,src:`${T(M,i.value,$,P)}`})}e.sort((u,a)=>u.screenMaxWidth-a.screenMaxWidth);const q=e[e.length-1];return q&&(q.media=""),{sizes:e.map(u=>`${u.media?u.media+" ":""}${u.size}`).join(", "),srcset:e.map(u=>`${u.src} ${u.width}w`).join(", "),src:q==null?void 0:q.src}};return{imageUrl:i,imageWidth:w,imageHeight:R,originalFormat:S,isTransparent:V,nFormat:x,nLegacyFormat:W,safeDimensions:z,nSources:J}},G=(t,o,s,r)=>({focalPoint:n.computed(()=>{const d=t*100/s,y=o*100/r;return{"object-position":`${d}% ${y}%`}})});p.useFocalPoint=G,p.usePicture=F,p.useRouteState=H,p.useURL=B,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
@@ -0,4 +1,4 @@ | ||
export { useRouteState } from './useRouteState'; | ||
export { useURL } from './useURL'; | ||
export { useRouteState } from './useRouteState'; | ||
export { usePicture } from './usePicture'; | ||
export { useFocalPoint } from './useFocalPoint'; |
@@ -37,3 +37,3 @@ import type { ComputedRef } from 'vue'; | ||
} | ||
export declare const usePicture: (image: ImageUrlObject | ImageFileObject, format: string, legacyFormat: string, mode: string, quality: number, sizesProp: string, screensProp: Record<string, number>, datoFocalPoint: FocalPointObject, datoAutoFormat: boolean) => { | ||
export declare const usePicture: (image: ImageUrlObject | ImageFileObject, format: string, legacyFormat: string, mode: string, quality: number, sizesProp: string, screensProp: Record<string, number>, datoFocalPoint: FocalPointObject, datoAutoFormat: boolean, sbFocalPoint: string) => { | ||
imageUrl: ComputedRef<string>; | ||
@@ -40,0 +40,0 @@ imageWidth: ComputedRef<number>; |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.0.0-40fc781", | ||
"version": "0.0.0-43cad3b", | ||
"license": "MIT", | ||
@@ -42,5 +42,4 @@ "files": [ | ||
"dependencies": { | ||
"@atoms-studio/nuxt-components": "0.0.0-40fc781", | ||
"mkdirp": "^0.5.5" | ||
} | ||
} |
2
-33.33%18761
-4.44%405
-2.17%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed