@impui/imp 1.0.18 → 1.0.21
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isString as t,isObject as e,isArray as r}from"@impui/com/typetool";import{injectCSS as i}from"@impui/com/style";import s from"../index.css/index.es.js";import{getConfig as n}from"../../config/index.es.js";i(s,"imp-restool");const o={};const c=new class{constructor(){this._config=null,this.initPromise=this.init()}async init(){return this._config||(this._config=await n()),this}async ensureConfig(){return this._config||await this.initPromise,this}get statics(){return this._config?{nohead:`${this._config.sr}/live/webSkins_site/${this._config.sitetype}/images/nohead.jpg`}:{nohead:""}}getSrc(i,s,n){if(!this._config)return"";let o=i;if(isNaN(parseInt(i))&&(o=this._config.paths.typeEnums[i]),t(i)&&["emblem","bubble","head","cardskin"].indexOf(i.toLowerCase())>=0&&(e(s)||r(s))&&0===(s=this.titlesTool.getTitlexIdFromType(s,i)))return"";if(4!==o&&0!=s&&!s)return"";o=parseInt(o);const c=this._config.paths.types[`t_${o}`],a=c.pc_path||c.path,l=c.pc_suffix||c.suffix;let g=this._config.js_version;if(n){g=impui.getCodeVer()[n]||this._config.js_version}return s||0===s?`${a}${s}${l}?d=${g}`:`${a}?d=${g}`}getEmotSrc(t,e,r=!1){return r?this.getSrc("emot",`${t}/${e}_s`):this.getSrc("emot",`${t}/${e}`)}getUserLevelSrc(t){return this.getSrc("user",t)}getAnchorLevelSrc(t){return this.getSrc("host",t)}getBubbleZipSrc(t){return this.getSrc("bubble_zip",t)}getFanclubLevelHtml(t,e){return`<span class="fanclubgrage" style="background-image:url(${this.getSrc("fans_grade",t)})">${e}</span>`}async getBubbleImageMap(t,e){const r=this.getBubbleZipSrc(t);return await this.getZipUrlMap(r,e)}getSrImgSrc(t){return t?t.startsWith("http")?t:`${this._config.sr}${t.startsWith("/")?t:"/"+t}`:""}async getZipUrlMap(t,e){await this.ensureConfig();const{jszip:r}=await impui.loadAsync(["jszip"]),i=new r;try{let r;if(o[t])r=o[t];else{const e=await fetch(t),s=await e.arrayBuffer();r=await i.loadAsync(s),o[t]=r}e=e||(()=>!0);const s={},n=[];r.forEach(async(t,r)=>{if(e(t,r)){const e=r.async("blob").then(e=>{const r=URL.createObjectURL(e);return{key:t,url:r}});n.push(e)}});return(await Promise.all(n)).forEach(t=>{s[t.key]=t.url}),s}catch(s){return console.error("获取压缩包失败:",s),null}}get titlesTool(){return{converTitlesex:i=>{if(!i)return{};if(e(i))return i;if(t(i))return JSON.parse(i);const s={};return r(i)&&i.forEach(t=>{s[t.titleid]=t}),s},getTitlesexFromType:(t,e)=>{const r=this.titlesTool.converTitlesex(t),i=[];for(const s in r){r[s].type===e&&i.push(parseInt(s))}return i},getTitlexIdFromType:(t,e)=>{const r=this.titlesTool.converTitlesex(t);let i=0,s=Number.MAX_VALUE;const n=e.toLowerCase();for(const o in r){const t=r[o];if(t.type.toLowerCase()===n){if("bubble"!==n)return parseInt(o);const e=parseInt(t.endtime);e<s&&(i=parseInt(o),s=e)}}return i},getHeadBorderSrc:t=>this.getSrc(7,t),getHeadBorderImg:t=>`<div class="border_img"><img src="${this.titlesTool.getHeadBorderSrc(t)}" /></div>`,getHeadBorder:(t,e)=>(t.addClass("headBorder"),t.append(this.titlesTool.getHeadBorderImg(e)),t)}}};export{c as restool};
|
|
1
|
+
import{isString as t,isObject as e,isArray as r}from"@impui/com/typetool";import{injectCSS as i}from"@impui/com/style";import s from"../index.css/index.es.js";import{getConfig as n}from"../../config/index.es.js";i(s,"imp-restool");const o={};const c=new class{constructor(){this._config=null,this.initPromise=this.init()}async init(){return this._config||(this._config=await n()),this}async ensureConfig(){return this._config||await this.initPromise,this}get statics(){return this._config?{nohead:`${this._config.sr}/live/webSkins_site/${this._config.sitetype}/images/nohead.jpg`}:{nohead:""}}getSrc(i,s,n){if(!this._config)return"";let o=i;if(isNaN(parseInt(i))&&(o=this._config.paths.typeEnums[i]),t(i)&&["emblem","bubble","head","cardskin"].indexOf(i.toLowerCase())>=0&&(e(s)||r(s))&&0===(s=this.titlesTool.getTitlexIdFromType(s,i)))return"";if(4!==o&&0!=s&&!s)return"";o=parseInt(o);const c=this._config.paths.types[`t_${o}`],a=c.pc_path||c.path,l=c.pc_suffix||c.suffix;let g=this._config.js_version;if(n){g=impui.getCodeVer()[n]||this._config.js_version}return s||0===s?`${a}${s}${l}?d=${g}`:`${a}?d=${g}`}getEmotSrc(t,e,r=!1){return r?this.getSrc("emot",`${t}/${e}_s`):this.getSrc("emot",`${t}/${e}`)}getUserLevelSrc(t){return this.getSrc("user",t)}getAnchorLevelSrc(t){return this.getSrc("host",t)}getBubbleZipSrc(t){return this.getSrc("bubble_zip",t)}getColorNickZipSrc(t){return this.getSrc("colornick",t)}getFanclubLevelHtml(t,e){return`<span class="fanclubgrage" style="background-image:url(${this.getSrc("fans_grade",t)})">${e}</span>`}async getBubbleImageMap(t,e){const r=this.getBubbleZipSrc(t);return await this.getZipUrlMap(r,e)}getSrImgSrc(t){return t?t.startsWith("http")?t:`${this._config.sr}${t.startsWith("/")?t:"/"+t}`:""}async getZipUrlMap(t,e){await this.ensureConfig();const{jszip:r}=await impui.loadAsync(["jszip"]),i=new r;try{let r;if(o[t])r=o[t];else{const e=await fetch(t),s=await e.arrayBuffer();r=await i.loadAsync(s),o[t]=r}e=e||(()=>!0);const s={},n=[];r.forEach(async(t,r)=>{if(e(t,r)){const e=r.async("blob").then(e=>{const r=URL.createObjectURL(e);return{key:t,url:r}});n.push(e)}});return(await Promise.all(n)).forEach(t=>{s[t.key]=t.url}),s}catch(s){return console.error("获取压缩包失败:",s),null}}get titlesTool(){return{converTitlesex:i=>{if(!i)return{};if(e(i))return i;if(t(i))return JSON.parse(i);const s={};return r(i)&&i.forEach(t=>{s[t.titleid]=t}),s},getTitlesexFromType:(t,e)=>{const r=this.titlesTool.converTitlesex(t),i=[];for(const s in r){r[s].type===e&&i.push(parseInt(s))}return i},getTitlexIdFromType:(t,e)=>{const r=this.titlesTool.converTitlesex(t);let i=0,s=Number.MAX_VALUE;const n=e.toLowerCase();for(const o in r){const t=r[o];if(t.type.toLowerCase()===n){if("bubble"!==n)return parseInt(o);const e=parseInt(t.endtime);e<s&&(i=parseInt(o),s=e)}}return i},getHeadBorderSrc:t=>this.getSrc(7,t),getHeadBorderImg:t=>`<div class="border_img"><img src="${this.titlesTool.getHeadBorderSrc(t)}" /></div>`,getHeadBorder:(t,e)=>(t.addClass("headBorder"),t.append(this.titlesTool.getHeadBorderImg(e)),t)}}};export{c as restool};
|