New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@atoms-studio/composables

Package Overview
Dependencies
Maintainers
7
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atoms-studio/composables - npm Package Compare versions

Comparing version 0.0.0-a5f4c95 to 0.0.0-a8bc262

dist/useFocalPoint.d.ts

266

dist/composables.es.js

@@ -1,2 +0,72 @@

import { computed } from "vue";
import { inject, computed } from "vue";
/*!
* vue-router v4.1.6
* (c) 2022 Eduardo San Martin Morote
* @license MIT
*/
var NavigationType;
(function(NavigationType2) {
NavigationType2["pop"] = "pop";
NavigationType2["push"] = "push";
})(NavigationType || (NavigationType = {}));
var NavigationDirection;
(function(NavigationDirection2) {
NavigationDirection2["back"] = "back";
NavigationDirection2["forward"] = "forward";
NavigationDirection2["unknown"] = "";
})(NavigationDirection || (NavigationDirection = {}));
var NavigationFailureType;
(function(NavigationFailureType2) {
NavigationFailureType2[NavigationFailureType2["aborted"] = 4] = "aborted";
NavigationFailureType2[NavigationFailureType2["cancelled"] = 8] = "cancelled";
NavigationFailureType2[NavigationFailureType2["duplicated"] = 16] = "duplicated";
})(NavigationFailureType || (NavigationFailureType = {}));
const routerKey = Symbol("");
const routeLocationKey = Symbol("");
function useRouter() {
return inject(routerKey);
}
function useRoute() {
return inject(routeLocationKey);
}
const useRouteState = (configOrKeys, method = "replace") => {
const route = useRoute();
const router = useRouter();
let config;
if (Array.isArray(configOrKeys)) {
config = configOrKeys.reduce((acc, key) => {
acc[key] = {
get: (value) => value,
set: (value) => value
};
return acc;
}, {});
} else {
config = configOrKeys;
}
const stateKeys = Object.keys(config);
const state = computed(() => {
const result = {};
for (const stateKey of stateKeys) {
const queryValue = route.query[stateKey];
const stateValue = config[stateKey].get(queryValue);
result[stateKey] = stateValue;
}
return result;
});
const updateState = (partialState) => {
const newState = { ...state.value, ...partialState };
const newQuery = {};
for (const stateKey of stateKeys) {
const stateValue = newState[stateKey];
const queryValue = config[stateKey].set(stateValue);
newQuery[stateKey] = queryValue;
}
return router[method]({ query: { ...route.query, ...newQuery } });
};
return {
state,
updateState
};
};
const useURL = (to, base) => {

@@ -32,2 +102,194 @@ if (!base) {

};
export { useURL };
const getFileExtension = (url) => {
var _a, _b, _c;
const extension = (_c = (_b = (_a = url.split(/[?#]/).shift()) == null ? void 0 : _a.split("/").pop()) == null ? void 0 : _b.split(".").pop()) != null ? _c : "jpg";
return extension;
};
const limitImageDimensions = (max, width = 0, height = 0) => {
if (width > max || height > max) {
const ratio = width / height;
const biggerDimension = Math.max(width, height);
if (biggerDimension === width) {
width = max;
height = Math.round(width / ratio);
} else {
height = max;
width = Math.round(height * ratio);
}
}
return {
width,
height
};
};
const parseSize = (input = "") => {
if (typeof input === "number") {
return input;
}
if (typeof input === "string") {
if (input.replace("px", "").match(/^\d+$/g)) {
return parseInt(input, 10);
}
}
};
const isCtfAsset = (url) => url && url.includes("ctfassets");
const isDatoAsset = (url) => url && url.includes("datocms-assets");
const isStoryblokAsset = (url) => url && url.includes("a.storyblok");
const usePicture = (image, format, legacyFormat, mode, quality, sizesProp, screensProp, datoFocalPoint, datoAutoFormat) => {
const imageUrl = computed(() => {
return "url" in image ? image.url : "file" in image ? image.file.url : "";
});
const imageWidth = computed(() => {
return "width" in image ? image.width : image && "file" in image ? image.file.details.image.width : 0;
});
const imageHeight = computed(() => {
return image && "height" in image ? image.height : image && "file" in image ? image.file.details.image.height : 0;
});
const originalFormat = computed(() => {
return getFileExtension(imageUrl.value);
});
const isTransparent = computed(() => {
return ["png", "webp", "gif"].includes(originalFormat.value);
});
const nFormat = computed(() => {
if (format) {
return format;
}
if (originalFormat.value === "svg") {
return "svg";
}
return "webp";
});
const nLegacyFormat = computed(() => {
if (legacyFormat) {
return legacyFormat;
}
const formats = {
webp: isTransparent.value ? "png" : "jpeg",
svg: "png"
};
return formats[nFormat.value] || originalFormat.value;
});
const safeDimensions = computed(() => {
return limitImageDimensions(4e3, imageWidth.value, imageHeight.value);
});
const nSources = computed(() => {
if (nFormat.value === "svg") {
return [
{
srcset: imageUrl.value
}
];
}
const formats = nLegacyFormat.value !== nFormat.value ? [nLegacyFormat.value, nFormat.value] : [nFormat.value];
const sources = formats.map((format2) => {
const { srcset, sizes, src } = getSizes(format2);
return {
src,
type: `image/${format2}`,
sizes,
srcset
};
});
return sources;
});
const createUrlImage = (breakPoint, url, format2 = "jpg", height) => {
let resizeParams = "";
if (isCtfAsset(url)) {
resizeParams = "?";
resizeParams += `w=${breakPoint}&`;
resizeParams += height ? `h=${height}&` : "";
resizeParams += mode ? `fit=${mode}&` : "";
resizeParams += `q=${quality}&fm=${format2 && format2 === "jpeg" ? "jpg" : format2}`;
}
if (isDatoAsset(url)) {
resizeParams = "?";
resizeParams += `crop=focalpoint&fit=crop&fp-x=${datoFocalPoint.x}&fp-y=${datoFocalPoint.y}&`;
resizeParams += `w=${breakPoint}&`;
resizeParams += height ? `h=${height}&` : "";
resizeParams += datoAutoFormat ? "auto=format&" : "";
resizeParams += `q=${quality}&fm=${format2 && format2 === "jpeg" ? "jpg" : format2}`;
}
if (isStoryblokAsset(url)) {
resizeParams = "/m/";
resizeParams += breakPoint && height ? `${breakPoint}x${height}` : breakPoint ? `${breakPoint}x0` : "";
}
return `${url}${resizeParams}`;
};
const getSizes = (format2) => {
const width = parseSize(safeDimensions.value.width);
const height = parseSize(safeDimensions.value.height);
const hwRatio = width && height ? height / width : 0;
const variants = [];
const sizes = {};
if (typeof sizesProp === "string") {
for (const entry of sizesProp.split(/[\s,]+/).filter((e) => e)) {
const s = entry.split(":");
if (s.length !== 2) {
continue;
}
sizes[s[0].trim()] = s[1].trim();
}
} else {
Object.assign(sizes, sizesProp);
}
for (const key in sizes) {
const screenMaxWidth = screensProp && screensProp[key] || parseInt(key);
let size = String(sizes[key]);
const isFluid = size.endsWith("vw");
if (!isFluid && /^\d+$/.test(size)) {
size = size + "px";
}
if (!isFluid && !size.endsWith("px")) {
continue;
}
let _cWidth = parseInt(size);
if (!screenMaxWidth || !_cWidth) {
continue;
}
if (isFluid) {
_cWidth = Math.round(_cWidth / 100 * screenMaxWidth);
}
const _cHeight = hwRatio ? Math.round(_cWidth * hwRatio) : height;
variants.push({
width: _cWidth,
size,
screenMaxWidth,
media: `(max-width: ${screenMaxWidth}px)`,
src: `${createUrlImage(_cWidth, imageUrl.value, format2, _cHeight)}`
});
}
variants.sort((v1, v2) => v1.screenMaxWidth - v2.screenMaxWidth);
const defaultVar = variants[variants.length - 1];
if (defaultVar) {
defaultVar.media = "";
}
return {
sizes: variants.map((v) => `${v.media ? v.media + " " : ""}${v.size}`).join(", "),
srcset: variants.map((v) => `${v.src} ${v.width}w`).join(", "),
src: defaultVar == null ? void 0 : defaultVar.src
};
};
return {
imageUrl,
imageWidth,
imageHeight,
originalFormat,
isTransparent,
nFormat,
nLegacyFormat,
safeDimensions,
nSources
};
};
const useFocalPoint = (x, y, width, height) => {
const focalPoint = computed(() => {
const focalX = x * 100 / width;
const focalY = y * 100 / height;
return { "object-position": `${focalX}% ${focalY}%` };
});
return {
focalPoint
};
};
export { useFocalPoint, usePicture, useRouteState, useURL };

@@ -1,1 +0,5 @@

(function(u,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(u=typeof globalThis!="undefined"?globalThis:u||self,e(u.MyLib={},u.Vue))})(this,function(u,e){"use strict";const s=(i,o)=>{if(!o)throw new Error("Base is required");const r=e.computed(()=>i.value==="#"),t=e.computed(()=>typeof i.value=="string"?new URL(i.value,o):null),l=e.computed(()=>{var n;return((n=t.value)==null?void 0:n.origin)||""}),d=e.computed(()=>{var n;return r.value?"#":((n=t.value)==null?void 0:n.pathname)||""}),c=e.computed(()=>r.value||t.value!==null&&l.value!==o);return{url:t,origin:l,path:d,isExternal:c,isDummy:r}};u.useURL=s,Object.defineProperty(u,"__esModule",{value:!0}),u[Symbol.toStringTag]="Module"});
(function(d,n){typeof exports=="object"&&typeof module!="undefined"?n(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],n):(d=typeof globalThis!="undefined"?globalThis:d||self,n(d.MyLib={},d.Vue))})(this,function(d,n){"use strict";/*!
* vue-router v4.1.6
* (c) 2022 Eduardo San Martin Morote
* @license MIT
*/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 V=Symbol(""),_=Symbol("");function E(){return n.inject(V)}function K(){return n.inject(_)}const k=(t,o="replace")=>{const s=K(),r=E();let c;Array.isArray(t)?c=t.reduce((h,l)=>(h[l]={get:f=>f,set:f=>f},h),{}):c=t;const m=Object.keys(c),y=n.computed(()=>{const h={};for(const l of m){const f=s.query[l],w=c[l].get(f);h[l]=w}return h});return{state:y,updateState:h=>{const l={...y.value,...h},f={};for(const w of m){const S=l[w],R=c[w].set(S);f[w]=R}return r[o]({query:{...s.query,...f}})}}},H=(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)||""}),m=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:m,isExternal:y,isDummy:s}},B=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"},C=(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)},F=t=>t&&t.includes("ctfassets"),O=t=>t&&t.includes("datocms-assets"),Q=t=>t&&t.includes("a.storyblok"),X=(t,o,s,r,c,m,y,g,h)=>{const l=n.computed(()=>"url"in t?t.url:"file"in t?t.file.url:""),f=n.computed(()=>"width"in t?t.width:t&&"file"in t?t.file.details.image.width:0),w=n.computed(()=>t&&"height"in t?t.height:t&&"file"in t?t.file.details.image.height:0),S=n.computed(()=>B(l.value)),R=n.computed(()=>["png","webp","gif"].includes(S.value)),b=n.computed(()=>o||(S.value==="svg"?"svg":"webp")),W=n.computed(()=>s||{webp:R.value?"png":"jpeg",svg:"png"}[b.value]||S.value),z=n.computed(()=>C(4e3,f.value,w.value)),G=n.computed(()=>b.value==="svg"?[{srcset:l.value}]:(W.value!==b.value?[W.value,b.value]:[b.value]).map(i=>{const{srcset:p,sizes:e,src:x}=T(i);return{src:x,type:`image/${i}`,sizes:e,srcset:p}})),J=($,j,i="jpg",p)=>{let e="";return F(j)&&(e="?",e+=`w=${$}&`,e+=p?`h=${p}&`:"",e+=r?`fit=${r}&`:"",e+=`q=${c}&fm=${i&&i==="jpeg"?"jpg":i}`),O(j)&&(e="?",e+=`crop=focalpoint&fit=crop&fp-x=${g.x}&fp-y=${g.y}&`,e+=`w=${$}&`,e+=p?`h=${p}&`:"",e+=h?"auto=format&":"",e+=`q=${c}&fm=${i&&i==="jpeg"?"jpg":i}`),Q(j)&&(e="/m/",e+=$&&p?`${$}x${p}`:$?`${$}x0`:""),`${j}${e}`},T=$=>{const j=U(z.value.width),i=U(z.value.height),p=j&&i?i/j:0,e=[],x={};if(typeof m=="string")for(const u of m.split(/[\s,]+/).filter(a=>a)){const a=u.split(":");a.length===2&&(x[a[0].trim()]=a[1].trim())}else Object.assign(x,m);for(const u in x){const a=y&&y[u]||parseInt(u);let v=String(x[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 Z=p?Math.round(M*p):i;e.push({width:M,size:v,screenMaxWidth:a,media:`(max-width: ${a}px)`,src:`${J(M,l.value,$,Z)}`})}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:l,imageWidth:f,imageHeight:w,originalFormat:S,isTransparent:R,nFormat:b,nLegacyFormat:W,safeDimensions:z,nSources:G}},Y=(t,o,s,r)=>({focalPoint:n.computed(()=>{const m=t*100/s,y=o*100/r;return{"object-position":`${m}% ${y}%`}})});d.useFocalPoint=Y,d.usePicture=X,d.useRouteState=k,d.useURL=H,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});

@@ -0,1 +1,4 @@

export { useRouteState } from './useRouteState';
export { useURL } from './useURL';
export { usePicture } from './usePicture';
export { useFocalPoint } from './useFocalPoint';

2

package.json

@@ -7,3 +7,3 @@ {

},
"version": "0.0.0-a5f4c95",
"version": "0.0.0-a8bc262",
"license": "MIT",

@@ -10,0 +10,0 @@ "files": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc