UNPKG

@lottiefiles/relottie-metadata

Version:
2 lines 2.53 kB
import{TITLES as F}from"@lottiefiles/last";import{visit as z}from"unist-util-visit";import{filesize as h}from"filesize";var S=o=>new Blob([o]).size,O=(o,t)=>Number(o)?{bytes:o,formated:h(o,t)}:{bytes:0,formated:"0 B"},p=(o,t)=>{let r=JSON.stringify(JSON.parse(o.value)),a=S(r);return O(a,t)};function m(o,t){if(o.length>4||o.length<3)return t?.message("RGBA color array must have 3 or 4 values."),"";let r=[];for(let a of o){if(a<0||a>1)return t?.message("RGBA color values must be between 0 and 1."),"";let e=Math.round(a*255).toString(16);r.push(e.length===1?`0${e}`:e)}return`#${r.join("")}`}var l=o=>/^#([\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/iu.test(o);var x={bits:!1,pad:!1,base:10,round:2,locale:"",localeOptions:{},separator:".",spacer:" ",symbols:{},standard:"iec",output:"object",fullform:!1,fullforms:[],exponent:-1,roundingMethod:"round",precision:0},c={fileSize:{enable:!0,options:x}};var{collection:y,number:n,object:s,string:f}=F,T=(o,t,r)=>{let a=o.children[0];if(!a)return;let e=a.value;if(!e)return;let i=o.title;switch(typeof e){case"number":switch(i){case n.framerate:if(r.title!==s.animation)return;t.framerate=e;break;case n.width:if(r.title!==s.animation)return;t.width=e;break;case n.height:if(r.title!==s.animation)return;t.height=e;break;case n.inPoint:if(r.title!==s.animation)return;t.inPoint=e;break;case n.outPoint:if(r.title!==s.animation)return;t.outPoint=e;break;default:break}break;case"string":switch(i){case f.version:t.version=e;break;case f.generator:t.generator=e;break;case f.hexColor:l(e)&&t.colors.add(e.toLowerCase());break;case f.themeColor:l(e)&&t.colors.add(e.toLowerCase());break;default:break}break;default:break}},k=o=>{let t=o.children[0];return t?t.children.reduce((a,e)=>{if(e.type!=="primitive")return a;let i=e.value;return typeof i=="number"&&a.push(i),a},[]):[]},v=(o,t,r)=>{switch(o.title){case y.colorRgba:let e=k(o),i=m(e,r).toLowerCase();l(i)&&t.colors.add(i);break;default:break}},P=(o={})=>{let t={...c,...o};function r(a,e){let i={colors:new Set,framerate:0,frames:0,inPoint:0,outPoint:0,generator:"",height:0,version:"",width:0};z(a,(u,N,g)=>{switch(u.type){case"attribute":T(u,i,g);break;case"collection":v(u,i,e);break;default:break}}),t.fileSize.enable&&Object.assign(i,{fileSize:p(e,t.fileSize.options)}),i.frames=i.outPoint-i.inPoint;let d={metadata:i};Object.assign(e.data,d)}return r},b=P;var B=b;export{c as DEFAULT_OPTIONS,B as default,O as formatBytes,S as getByteSize,p as getFileSize,l as isHexValid,m as rgbaToHex}; //# sourceMappingURL=index.js.map