hexo-bitiful-toolkit 1.0.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/dist/index.js +6 -9
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -58,7 +58,6 @@ bitiful_toolkit:
|
|
|
58
58
|
add_max_width: false
|
|
59
59
|
max_widths: "(max-width: 600px) 100vw, (max-width: 1200px) 50vw, 800px"
|
|
60
60
|
enable_lazy_loading: true
|
|
61
|
-
lazy_skip_first: 2
|
|
62
61
|
supported_domains: ["assets.vluv.space", "s3.bitiful.net", "bitiful.com"]
|
|
63
62
|
exclude_formats: ['svg', 'gif'],
|
|
64
63
|
inject_css: true
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
var Q=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var at=Q((
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
${i}
|
|
8
|
-
background-size: cover;
|
|
9
|
-
background-repeat: no-repeat;">${h}</div>`:h}async function Tt(e,t){let s={srcset_widths:[400,600,800,1200,2e3,3e3],add_max_width:!1,max_widths:"(max-width: 600px) 100vw, (max-width: 1200px) 50vw, 800px",enable_lazy_loading:!0,lazy_skip_first:2,supported_domains:["assets.vluv.space","s3.bitiful.net","bitiful.com"],exclude_formats:["svg","gif"],...t},c=global.bitifulCacheInstance,o=/<img[^>]+src="(.+?)"[^>]*>/gm,n=Array.from(e.matchAll(o));if(n.length===0)return e;let r=new Map;n.forEach(y=>{let[m,d]=y;$t(d,s.supported_domains,s.exclude_formats)&&(r.has(d)||r.set(d,{src:d}))});let l=Array.from(r.keys()),p=await Promise.all(l.map(async y=>{let[m,d]=await Promise.all([wt(y,c),Ft(y,c)]);return{src:y,thumbhash:m,dimensions:d}})),g=new Map(p.map(y=>[y.src,y])),h="",i=0,f=0;for(let y of n){let[m,d]=y,$=y.index;h+=e.slice(i,$);let L=g.get(d);if(L){let H=s.enable_lazy_loading&&++f>s.lazy_skip_first;h+=Lt(m,d,s,H,L.thumbhash,L.dimensions)}else h+=m;i=$+m.length}return h+=e.slice(i),h}ht.exports=Tt});var ut=ft(),vt=et(),T=hexo.log,Bt=hexo.config.bitiful_toolkit?.env_name||"CI";function Ut(){if(!hexo.config.bitiful_toolkit||!hexo.config.bitiful_toolkit.enable||process.env[Bt]!=="true")return;let e=new vt({...hexo.config.bitiful_toolkit.cache,hexo_root:hexo.base_dir});global.bitifulCacheInstance=e,hexo.extend.filter.register("before_generate",async()=>{T.info("[BITIFUL] Initializing thumbhash cache..."),await e.loadCacheFromFile();let t=e.getStats();T.info(`[BITIFUL] Cache initialized with ${t.totalItems} items`)},8),hexo.extend.filter.register("after_generate",async()=>{if(e){let t=e.getStats();T.info("[BITIFUL] \u56FE\u7247\u5904\u7406\u5B8C\u6210\u7EDF\u8BA1:"),T.info(`[BITIFUL] - \u603B\u8BF7\u6C42\u6570: ${t.totalRequests}`),T.info(`[BITIFUL] - \u5B9E\u9645API\u8BF7\u6C42\u6570: ${t.apiRequests}`),T.info(`[BITIFUL] - \u7F13\u5B58\u547D\u4E2D\u6570: ${t.cacheHits}`),T.info(`[BITIFUL] - \u7F13\u5B58\u547D\u4E2D\u7387: ${t.cacheHitRate}%`),T.info(`[BITIFUL] - \u7F13\u5B58\u603B\u6761\u76EE\u6570: ${t.totalItems}`),t.isDirty?(T.info("[BITIFUL] Saving updated cache to local file..."),await e.saveCacheToFile()):T.info("[BITIFUL] No cache updates, skipping save")}}),hexo.config.bitiful_toolkit.all?(T.info("[BITIFUL] process all image"),hexo.extend.filter.register("after_render:html",async t=>(t=await ut(t,hexo.config.bitiful_toolkit),t),15)):(T.info("[BITIFUL] process post images"),hexo.extend.filter.register("before_post_render",async t=>(t.content=await ut(t.content,hexo.config.bitiful_toolkit),t),15))}Ut();
|
|
1
|
+
var Q=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var at=Q((Dt,nt)=>{function mt(e,t,s){if(e>100||t>100)throw new Error(`${e}x${t} doesn't fit in 100x100`);let{PI:o,round:c,max:n,cos:l,abs:f}=Math,d=0,m=0,h=0,r=0;for(let x=0,g=0;x<e*t;x++,g+=4){let p=s[g+3]/255;d+=p/255*s[g],m+=p/255*s[g+1],h+=p/255*s[g+2],r+=p}r&&(d/=r,m/=r,h/=r);let a=r<e*t,I=a?5:7,T=n(1,c(I*e/n(e,t))),C=n(1,c(I*t/n(e,t))),w=[],$=[],O=[],W=[];for(let x=0,g=0;x<e*t;x++,g+=4){let p=s[g+3]/255,R=d*(1-p)+p/255*s[g],i=m*(1-p)+p/255*s[g+1],u=h*(1-p)+p/255*s[g+2];w[x]=(R+i+u)/3,$[x]=(R+i)/2-u,O[x]=R-i,W[x]=p}let S=(x,g,p)=>{let R=0,i=[],u=0,y=[];for(let b=0;b<p;b++)for(let j=0;j*p<g*(p-b);j++){let E=0;for(let U=0;U<e;U++)y[U]=l(o/e*j*(U+.5));for(let U=0;U<t;U++)for(let K=0,gt=l(o/t*b*(U+.5));K<e;K++)E+=x[K+U*e]*y[K]*gt;E/=e*t,j||b?(i.push(E),u=n(u,f(E))):R=E}if(u)for(let b=0;b<i.length;b++)i[b]=.5+.5/u*i[b];return[R,i,u]},[G,k,V]=S(w,n(3,T),n(3,C)),[X,J,Y]=S($,3,3),[N,A,P]=S(O,3,3),[H,M,z]=a?S(W,5,5):[],q=e>t,_=c(63*G)|c(31.5+31.5*X)<<6|c(31.5+31.5*N)<<12|c(31*V)<<18|a<<23,D=(q?C:T)|c(63*Y)<<3|c(63*P)<<9|q<<15,L=[_&255,_>>8&255,_>>16,D&255,D>>8],v=a?6:5,B=0;a&&L.push(c(15*H)|c(15*z)<<4);for(let x of a?[k,J,A,M]:[k,J,A])for(let g of x)L[v+(B>>1)]|=c(15*g)<<((B++&1)<<2);return new Uint8Array(L)}function st(e){let{PI:t,min:s,max:o,cos:c,round:n}=Math,l=e[0]|e[1]<<8|e[2]<<16,f=e[3]|e[4]<<8,d=(l&63)/63,m=(l>>6&63)/31.5-1,h=(l>>12&63)/31.5-1,r=(l>>18&31)/31,a=l>>23,I=(f>>3&63)/63,T=(f>>9&63)/63,C=f>>15,w=o(3,C?a?5:7:f&7),$=o(3,C?f&7:a?5:7),O=a?(e[5]&15)/15:1,W=(e[5]>>4)/15,S=a?6:5,G=0,k=(q,_,D)=>{let L=[];for(let v=0;v<_;v++)for(let B=v?0:1;B*_<q*(_-v);B++)L.push(((e[S+(G>>1)]>>((G++&1)<<2)&15)/7.5-1)*D);return L},V=k(w,$,r),X=k(3,3,I*1.25),J=k(3,3,T*1.25),Y=a&&k(5,5,W),N=ot(e),A=n(N>1?32:32*N),P=n(N>1?32/N:32),H=new Uint8Array(A*P*4),M=[],z=[];for(let q=0,_=0;q<P;q++)for(let D=0;D<A;D++,_+=4){let L=d,v=m,B=h,x=O;for(let i=0,u=o(w,a?5:3);i<u;i++)M[i]=c(t/A*(D+.5)*i);for(let i=0,u=o($,a?5:3);i<u;i++)z[i]=c(t/P*(q+.5)*i);for(let i=0,u=0;i<$;i++)for(let y=i?0:1,b=z[i]*2;y*$<w*($-i);y++,u++)L+=V[u]*M[y]*b;for(let i=0,u=0;i<3;i++)for(let y=i?0:1,b=z[i]*2;y<3-i;y++,u++){let j=M[y]*b;v+=X[u]*j,B+=J[u]*j}if(a)for(let i=0,u=0;i<5;i++)for(let y=i?0:1,b=z[i]*2;y<5-i;y++,u++)x+=Y[u]*M[y]*b;let g=L-2/3*v,p=(3*L-g+B)/2,R=p-B;H[_]=o(0,255*s(1,p)),H[_+1]=o(0,255*s(1,R)),H[_+2]=o(0,255*s(1,g)),H[_+3]=o(0,255*s(1,x))}return{w:A,h:P,rgba:H}}function xt(e){let{min:t,max:s}=Math,o=e[0]|e[1]<<8|e[2]<<16,c=(o&63)/63,n=(o>>6&63)/31.5-1,l=(o>>12&63)/31.5-1,d=o>>23?(e[5]&15)/15:1,m=c-2/3*n,h=(3*c-m+l)/2,r=h-l;return{r:s(0,t(1,h)),g:s(0,t(1,r)),b:s(0,t(1,m)),a:d}}function ot(e){let t=e[3],s=e[2]&128,o=e[4]&128,c=o?s?5:7:t&7,n=o?t&7:s?5:7;return c/n}function ct(e,t,s){let o=e*4+1,c=6+t*(5+o),n=[137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,e>>8,e&255,0,0,t>>8,t&255,8,6,0,0,0,0,0,0,0,c>>>24,c>>16&255,c>>8&255,c&255,73,68,65,84,120,1],l=[0,498536548,997073096,651767980,1994146192,1802195444,1303535960,1342533948,-306674912,-267414716,-690576408,-882789492,-1687895376,-2032938284,-1609899400,-1111625188],f=1,d=0;for(let m=0,h=0,r=o-1;m<t;m++,r+=o-1)for(n.push(m+1<t?0:1,o&255,o>>8,~o&255,o>>8^255,0),d=(d+f)%65521;h<r;h++){let a=s[h]&255;n.push(a),f=(f+a)%65521,d=(d+f)%65521}n.push(d>>8,d&255,f>>8,f&255,0,0,0,0,0,0,0,0,73,69,78,68,174,66,96,130);for(let[m,h]of[[12,29],[37,41+c]]){let r=-1;for(let a=m;a<h;a++)r^=n[a],r=r>>>4^l[r&15],r=r>>>4^l[r&15];r=~r,n[h++]=r>>>24,n[h++]=r>>16&255,n[h++]=r>>8&255,n[h++]=r&255}return`data:image/png;base64,${btoa(String.fromCharCode(...n))}`}function bt(e){let t=st(e);return ct(t.w,t.h,t.rgba)}nt.exports={rgbaToThumbHash:mt,thumbHashToRGBA:st,thumbHashToAverageRGBA:xt,thumbHashToApproximateAspectRatio:ot,rgbaToDataURL:ct,thumbHashToDataURL:bt}});var lt=Q((Rt,rt)=>{var{thumbHashToDataURL:It}=at();function Z(e){return e.split("?")[0]}async function it(e,t){let s=`${Z(e)}?fmt=${t}`,o=await fetch(s);if(!o.ok)throw new Error(`Fetch ${t} failed: ${o.statusText}`);return o}async function yt(e,t=null){try{if(t){let l=t.getCachedDimensions(e);if(l)return l}let s=Z(e).split("/").pop();console.log(`[BITIFUL] \u274C ${s} \u5C3A\u5BF8\u7F13\u5B58\u672A\u547D\u4E2D`);let o=await it(e,"info"),{ImageWidth:c,ImageHeight:n}=await o.json();if(typeof c=="number"&&typeof n=="number"){let l={width:c,height:n};return t?.setCachedDimensions(e,c,n),l}return null}catch(s){return console.warn(`[BITIFUL] Dimension error for ${e}:`,s.message),null}}async function _t(e,t=null){try{if(t){let f=t.getCachedDataURL(e);if(f)return f}let s=Z(e).split("/").pop();console.log(`[BITIFUL] \u274C ${s} Hash\u7F13\u5B58\u672A\u547D\u4E2D`);let c=await(await it(e,"thumbhash")).text(),n=new Uint8Array(Buffer.from(c.trim(),"base64")),l=It(n);return l&&t&&t.setCachedDataURL(e,l),l}catch(s){return console.warn(`[BITIFUL] Thumbhash error for ${e}:`,s.message),null}}rt.exports={getDimension:yt,getDataURL:_t}});var ft=Q((kt,ht)=>{var{getDimension:Ft,getDataURL:wt}=lt();function $t(e,t,s){let o=t.some(l=>e.includes(l)),c=e.split(".").pop().split("?")[0].toLowerCase(),n=!s.includes(c);return o&&n}function Lt(e,t,s,o,c,n){let l=s.srcset_widths.map(a=>`${t.includes("?")?`${t}&w=${a}`:`${t}?w=${a}`} ${a}w`).join(", "),f=e.replace(/<img\s+/i,"").replace(/\s*\/?>$/i,"").replace(/\b(src|width|srcset|loading|style)\s*=\s*["'][^"']*["']/gi,""),d=e.match(/\bwidth\s*=\s*["']?([^"'\s>]+)/i),h=["position: relative","overflow: hidden",`width: ${d?Number.isNaN(d[1])?d[1]:`${d[1]}px`:"100%"}`,`background-image: url('${c}')`,"background-size: cover","background-repeat: no-repeat","margin: auto"];n?.width&&(h.push(`max-width: ${n.width}px`),h.push(`aspect-ratio: ${n.width} / ${n.height}`));let r=`<img src="${t}"
|
|
2
|
+
srcset="${l}"
|
|
3
|
+
${o?'loading="lazy" decoding="async"':""}
|
|
4
|
+
style="width:100%; height:100%; object-fit:cover; transition: opacity 0.3s; ${c?"opacity:0;":""}"
|
|
5
|
+
onload="this.style.opacity=1; this.parentElement.style.backgroundImage='none';"
|
|
6
|
+
${f.trim()}>`;return c?`<div class="pic" style="${h.join(";")}">${r}</div>`:r}async function Tt(e,t){let s={srcset_widths:[400,600,800,1200,2e3,3e3],add_max_width:!1,max_widths:"(max-width: 600px) 100vw, (max-width: 1200px) 50vw, 800px",enable_lazy_loading:!0,supported_domains:["assets.vluv.space","s3.bitiful.net","bitiful.com"],exclude_formats:["svg","gif"],...t},o=global.bitifulCacheInstance,c=/<img[^>]+src="(.+?)"[^>]*>/gm,n=Array.from(e.matchAll(c));if(n.length===0)return e;let l=new Map;n.forEach(a=>{let I=a[1];$t(I,s.supported_domains,s.exclude_formats)&&l.set(I,null)});let f=Array.from(l.keys()),d=await Promise.all(f.map(async a=>{let[I,T]=await Promise.all([wt(a,o),Ft(a,o)]);return{src:a,thumbhash:I,dimensions:T}})),m=new Map(d.map(a=>[a.src,a])),h="",r=0;for(let a of n){let[I,T]=a,C=a.index;h+=e.slice(r,C);let w=m.get(T);if(w){let $=s.enable_lazy_loading;h+=Lt(I,T,s,$,w.thumbhash,w.dimensions)}else h+=I;r=C+I.length}return h+=e.slice(r),h}ht.exports=Tt});var dt=Q((At,ut)=>{var tt=require("node:fs/promises"),vt=require("node:path"),et=class{constructor(t={}){this.config={cache_file:"thumbcache.json",hexo_root:process.cwd(),...t},this.cache={},this.hasUpdated=!1,this.cacheFilePath=vt.join(this.config.hexo_root,this.config.cache_file),this.stats={apiRequests:0,cacheHits:0}}async loadCacheFromFile(){try{if(console.log("[BITIFUL] Loading cache from local file..."),await tt.access(this.cacheFilePath).then(()=>!0).catch(()=>!1)){let t=await tt.readFile(this.cacheFilePath,"utf8");this.cache=JSON.parse(t||"{}"),console.log(`[BITIFUL] Cache loaded from ${this.cacheFilePath}, ${Object.keys(this.cache).length} items`)}else console.log("[BITIFUL] Cache file not found, starting with empty cache"),this.cache={};return!0}catch(t){return console.warn("[BITIFUL] Failed to load cache from file:",t.message),this.cache={},!1}}async saveCacheToFile(){if(!this.config.enable||!this.hasUpdated)return console.log("[BITIFUL] Skipping cache save: disabled or no changes"),!1;try{console.log("[BITIFUL] Saving cache to local file...");let t=JSON.stringify(this.cache,null,2);return await tt.writeFile(this.cacheFilePath,t,"utf8"),console.log(`[BITIFUL] Cache saved to ${this.cacheFilePath}, ${Object.keys(this.cache).length} items`),this.hasUpdated=!1,!0}catch(t){return console.warn("[BITIFUL] Failed to save cache to file:",t.message),!1}}getCachedDataURL(t){if(this.cache[t]){this.stats.cacheHits++;let s=this.cache[t];return typeof s=="string"?s:s&&typeof s=="object"&&s.dataURL||null}return this.stats.apiRequests++,null}getCachedDimensions(t){let s=this.cache[t];return s?(this.stats.cacheHits++,typeof s=="object"&&Number.isFinite(s?.width)&&Number.isFinite(s?.height)?{width:s.width,height:s.height}:null):(this.stats.apiRequests++,null)}setCachedDataURL(t,s){if(!s)return;let o=this.cache[t];typeof o=="object"?o.dataURL!==s&&(this.cache[t]={...o,dataURL:s},this.hasUpdated=!0):o!==s&&(this.cache[t]={dataURL:s},this.hasUpdated=!0)}setCachedDimensions(t,s,o){if(!Number.isFinite(s)||!Number.isFinite(o))return;let c=this.cache[t];(c.width!==s||c.height!==o)&&(this.cache[t]={...c,width:s,height:o},this.hasUpdated=!0)}getStats(){let t=this.stats.apiRequests+this.stats.cacheHits;return{totalItems:Object.keys(this.cache).length,isDirty:this.hasUpdated,cacheEnabled:this.config.enable,...this.stats,totalRequests:t,cacheHitRate:t>0?(this.stats.cacheHits/t*100).toFixed(1):0}}};ut.exports=et});var pt=ft(),Bt=dt(),F=hexo.log,Ut=hexo.config.bitiful_toolkit?.env_name||"CI";function Ct(){if(!hexo.config.bitiful_toolkit||!hexo.config.bitiful_toolkit.enable||process.env[Ut]!=="true")return;let e=new Bt({...hexo.config.bitiful_toolkit.cache,hexo_root:hexo.base_dir});global.bitifulCacheInstance=e,hexo.extend.filter.register("before_generate",async()=>{F.info("[BITIFUL] Initializing thumbhash cache..."),await e.loadCacheFromFile();let t=e.getStats();F.info(`[BITIFUL] Cache initialized with ${t.totalItems} items`)},8),hexo.extend.filter.register("after_generate",async()=>{if(e){let t=e.getStats();F.info("[BITIFUL] \u56FE\u7247\u5904\u7406\u5B8C\u6210\u7EDF\u8BA1:"),F.info(`[BITIFUL] - \u603B\u8BF7\u6C42\u6570: ${t.totalRequests}`),F.info(`[BITIFUL] - \u5B9E\u9645API\u8BF7\u6C42\u6570: ${t.apiRequests}`),F.info(`[BITIFUL] - \u7F13\u5B58\u547D\u4E2D\u6570: ${t.cacheHits}`),F.info(`[BITIFUL] - \u7F13\u5B58\u547D\u4E2D\u7387: ${t.cacheHitRate}%`),F.info(`[BITIFUL] - \u7F13\u5B58\u603B\u6761\u76EE\u6570: ${t.totalItems}`),t.isDirty?(F.info("[BITIFUL] Saving updated cache to local file..."),await e.saveCacheToFile()):F.info("[BITIFUL] No cache updates, skipping save")}}),hexo.config.bitiful_toolkit.all?(F.info("[BITIFUL] process all image"),hexo.extend.filter.register("after_render:html",async t=>(t=await pt(t,hexo.config.bitiful_toolkit),t),15)):(F.info("[BITIFUL] process post images"),hexo.extend.filter.register("before_post_render",async t=>(t.content=await pt(t.content,hexo.config.bitiful_toolkit),t),15))}Ct();
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hexo-bitiful-toolkit",
|
|
3
3
|
"main": "dist/index.js",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.1.2",
|
|
5
|
+
"author": "GnixAij",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Efterklang/Bitiful_Responsive_And_Progressive_Image.git"
|
|
9
|
+
},
|
|
5
10
|
"files": [
|
|
6
11
|
"dist/index.js",
|
|
7
12
|
"README.md"
|