koishi-plugin-manosaba-text-box 1.0.13 → 1.0.15
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 -2
- package/lib/index.cjs +1 -1
- package/lib/index.mjs +2 -2
- package/package.json +5 -5
package/README.md
CHANGED
package/lib/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`koishi`),l=require(`node:fs/promises`);l=s(l);let u=require(`node:path`);u=s(u);let d=require(`node:module`),f=require(`node:url`),p=require(`@takumi-rs/wasm/
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`koishi`),l=require(`node:fs/promises`);l=s(l);let u=require(`node:path`);u=s(u);let d=require(`node:module`),f=require(`node:url`),p=require(`@takumi-rs/wasm/node`),m=require(`@takumi-rs/helpers`),h=require(`node:crypto`),g=require(`jieba-wasm`),_=require(`wasm-vips`);_=s(_);let v=require(`js-yaml`);v=s(v);const y={};let b=-1;function x(e,t=`manosaba-text-box`){let n=y[t]||e.logger(t);return b>=0&&(n.level=b),y[t]=n,n}function S(e){b=e;for(let t in y)y[t].level=e}function C(e){if(e.length<=1)return[...e];let t=[...e],n=new Uint32Array(t.length);h.webcrypto.getRandomValues(n);for(let e=t.length-1;e>0;e--){let r=n[e]%(e+1);[t[e],t[r]]=[t[r],t[e]]}return t}async function w(e){let t=await l.readFile(e,`utf-8`);return v.load(t)}const T=typeof __dirname<`u`?__dirname:u.dirname((0,f.fileURLToPath)(require(`url`).pathToFileURL(__filename).href)),E=typeof __dirname<`u`&&typeof require<`u`?require:(0,d.createRequire)(require(`url`).pathToFileURL(__filename).href);let D=null;const O={debug(e,t){D?.debug(e,t)},info(e,t){D?.info(e,t)},warn(e,t){D?.warn(e,t)},error(e,t){D?.error(e,t)}};function k(e){D=e}const A=global.__manosaba_takumi_state||{initialized:!1,initializing:null,renderer:null};global.__manosaba_takumi_state||(global.__manosaba_takumi_state=A);const j=(0,_.default)({dynamicLibraries:[`vips-heif.wasm`]}).then(e=>(e.concurrency(1),e.Cache.max(0),O.debug(`wasm-vips initialized with AVIF support`),e));let M=null;async function N(){return M||=await j,M}async function P(){if(A.initialized&&A.renderer)return A.renderer;if(A.initializing){if(await A.initializing,!A.renderer)throw Error(`Renderer failed to initialize`);return A.renderer}if(A.initializing=(async()=>{try{let e=E.resolve(`@takumi-rs/wasm/takumi_wasm_bg.wasm`);await l.readFile(e),A.renderer=new p.Renderer,A.initialized=!0,O.debug(`Takumi WASM initialized successfully`)}catch(e){throw O.error(`Failed to initialize takumi wasm`,{err:e}),A.initializing=null,e}})(),await A.initializing,!A.renderer)throw Error(`Renderer failed to initialize`);return A.renderer}let F=``,I={},L={},R=[];const z=new Map,B=new Map;let V=0;const ee=[[728,355],[2500,800]];function H(){return R}async function te(e,t){let n=t||T;F=u.join(n,`assets`);let r=u.join(n,`config`),i=u.join(r,`chara_meta.yml`),a=u.join(r,`text_configs.yml`);try{let[e,t,n]=await Promise.all([w(i),w(a),l.readdir(u.join(F,`background`))]);I=e.mahoshojo||{},L=t.text_configs||{},V=n.filter(e=>e.startsWith(`c`)&&e.endsWith(`.avif`)).length,R=Object.entries(I).map(([e,t])=>({id:e,name:t.full_name})),O.debug(`Loaded character meta and text configs`,{characters:Object.keys(I).length,textConfigs:Object.keys(L).length,backgrounds:V})}catch(e){O.error(`Failed to load config files`,{err:e})}}async function U(e){let t=z.get(e);if(t)return t;let n=await l.readFile(e);return z.set(e,n),n}async function W(e){let t=B.get(e);if(t)return t;let n=await l.readFile(e);return B.size<20&&B.set(e,n),n}async function ne(){if(V===0){let e=u.join(F,`background`);V=(await l.readdir(e)).filter(e=>e.startsWith(`c`)&&e.endsWith(`.avif`)).length}return C(Array.from({length:V},(e,t)=>t+1))[0]}function re(e){let t=I[e];return t?C(Array.from({length:t.emotion_count},(e,t)=>t+1))[0]:1}function G(e){let t=e.charCodeAt(0);return t>=19968&&t<=40959||t>=12352&&t<=12543||t>=65280&&t<=65519||t>=12288&&t<=12351}function ie(e){return/[-—–.,;:!?"'`~()[\]{}<>/\\|]/.test(e)}function K(e,t){return/\s/.test(e)?t*.25:G(e)?t:ie(e)?t*.35:t*.5}function ae(e,t){let n=0;for(let r of e)n+=K(r,t);return n}const q=1.2;async function J(e,t,n){let r=Math.max(0,t-12)*.9,i=[],a=e.split(/\n/);for(let e=0;e<a.length;e++){let t=a[e];if(t.trim().length===0){i.push(``);continue}let o=(0,g.cut)(t),s=``,c=0;for(let e=0;e<o.length;e++){let t=o[e],a=ae(t,n),l=s&&!/^[\s\u3000-\u303f\uff00-\uffef]/.test(t)&&!G(t[0])&&!G(s[s.length-1]),u=l?K(` `,n):0;if(c+u+a<=r)l&&(s+=` `),s+=t,c+=u+a;else if(a>r){s&&(i.push(s),s=``,c=0);let e=``,a=0;for(let o of t){let t=K(o,n);a+t>r?(i.push(e),e=o,a=t):(e+=o,a+=t)}s=e,c=a}else s&&i.push(s),s=t,c=a}s&&i.push(s)}return i.length===0&&e&&i.push(e),i}function Y(e){return{width:e.readUInt32BE(16),height:e.readUInt32BE(20)}}async function X(e){let t=await N(),n=null;try{n=t.Image.newFromBuffer(e);let r=n.writeToBuffer(`.png`,{compression:6});return Buffer.from(r)}catch(e){throw O.error(`Failed to convert AVIF to PNG`,{err:e}),e}finally{if(n)try{n[Symbol.dispose]()}catch{}}}async function oe(e,t,n){let r=await P();try{let i=u.join(F,`background`,`c${t}.avif`),a=u.join(F,`chara`,e,`${e} (${n}).avif`);O.debug(`Loading images`,{backgroundPath:i,characterPath:a});let[o,s]=await Promise.all([W(i),W(a)]);O.debug(`Converting AVIF to PNG for Takumi rendering`);let[c,l]=await Promise.all([X(o),X(s)]),{width:d,height:f}=Y(c);O.debug(`Background image dimensions`,{width:d,height:f}),r.putPersistentImage({src:i,data:new Uint8Array(c)}),r.putPersistentImage({src:a,data:new Uint8Array(l)});let p=(0,m.container)({children:[(0,m.image)({src:i,style:{width:d,height:f}}),(0,m.image)({src:a,style:{position:`absolute`,top:134,left:0}})],style:{position:`relative`,width:d,height:f,display:`block`}});if(L[e]){let t=I[e]?.font||`font3.ttf`,n=await U(u.join(F,`fonts`,t));r.loadFont(n);let o=L[e].filter(e=>e.text).map(e=>{let t=`rgb(${e.font_color.join(`,`)})`;return(0,m.container)({style:{position:`absolute`,left:e.position[0],top:e.position[1]},children:[(0,m.text)(e.text,{fontSize:e.font_size,color:t})]})}),s=(0,m.container)({children:[(0,m.image)({src:i,style:{width:d,height:f}}),(0,m.image)({src:a,style:{position:`absolute`,top:134,left:0}}),...o],style:{position:`relative`,width:d,height:f,display:`block`}}),c=r.render(s,{width:d,height:f,format:`png`});return Buffer.from(c)}let h=r.render(p,{width:d,height:f,format:`png`});return Buffer.from(h)}catch(e){throw O.error(`Failed to generate base image`,{err:e}),e}}async function se(e,t,n,r,i){O.debug(`drawUserText called`,{text:t,textLength:t.length,initialFontSize:r,fontPath:i,boxRect:n});try{let a=await P(),[[o,s],[c,l]]=n,u=c-o,d=l-s,f=Math.max(0,u-30-10),p=Math.max(0,d-20),h=await U(i);O.debug(`Font file loaded`,{fontPath:i,size:h.length}),a.loadFont(h);let g=r,_=async e=>{let n=await J(t,f,e),r=e*q;return 12+n.length*r<=p},v=40,y=r,b=v;for(;v<=y;){let e=Math.floor((v+y)/2);await _(e)?(b=e,v=e+1):y=e-1}g=b,O.debug(`Auto-adjusted font size`,{originalSize:r,adjustedSize:g,textLength:t.length});let{width:x,height:S}=Y(e),C=`base-image-${Date.now()}-${Math.random()}.png`;a.putPersistentImage({src:C,data:new Uint8Array(e)});let w=o+30,T=s+10,E=await J(t,f,g),D=g*q,k=E.map((e,t)=>(0,m.container)({style:{position:`absolute`,left:0,top:t*D},children:[(0,m.text)(e,{fontSize:g,color:`white`})]})),A=(0,m.container)({children:[(0,m.image)({src:C,style:{width:x,height:S}}),(0,m.container)({children:k,style:{position:`absolute`,left:w,top:T}})],style:{position:`relative`,width:x,height:S,display:`block`}}),j=a.render(A,{width:x,height:S,format:`png`});return O.debug(`Text drawing completed successfully`,{outputSize:j.length}),Buffer.from(j)}catch(t){return O.error(`Failed to draw text`,{err:t}),e}}async function Z(e,t,n,r,i,a){if(!I[t])throw Error(`Unknown character: ${t}`);let o=i??await ne(),s=a??re(t);O.debug(`Generating text box image`,{character:t,backgroundIndex:o,emotionIndex:s,textLength:n.length});let c=await oe(t,o,s),l=I[t]?.font||`font3.ttf`;return await se(c,n,ee,160,u.join(F,`fonts`,l))}var Q=class extends c.Service{constructor(e,t){super(e,`manosaba`,!0),this.config=t}async generateImage(e){let{character:t=this.config.defaultCharacter,text:n,backgroundIndex:r,emotionIndex:i}=e;if(!n||n.trim().length===0)throw Error(`文本内容不能为空`);try{return await Z(this.ctx,t,n,this.config,r,i)}catch(e){throw this.ctx.logger.error(`生成图片失败`,{error:e}),e}}getCharacters(){return H()}};const ce=c.Schema.object({defaultCharacter:c.Schema.union([`ema`,`hiro`,`sherri`,`hanna`,`nanoka`,`noa`,`miria`,`yuki`,`coco`,`meruru`,`reia`,`warden`,`mago`,`alisa`,`anan`]).default(`ema`).description(`默认使用的角色`),isLog:c.Schema.boolean().default(!1).description(`是否输出 debug 日志`)});let $;function le(e,t){$=x(e),ue(t),k($),e.on(`ready`,async()=>{await te(e,__dirname)}),e.plugin(Q,t),e.command(`mtb <text:text>`,`生成魔女裁判文本框图片`).option(`character`,`-c <character:string>`,{fallback:t.defaultCharacter}).action(async({session:n,options:r},i)=>{if(!i||i.trim()===``)return`请输入要生成的文本内容`;try{let a=await Z(e,r.character,i,t);await n.send(c.h.image(a,`image/png`))}catch(e){return $.error(`生成图片失败`,{err:e}),`生成图片失败: ${e.message}`}}),e.command(`mtb.list`,`列出所有可用的角色`).action(()=>{let e=H();return e.length===0?`暂无可用角色`:`可用角色列表:\n${e.map(e=>`${e.id}: ${e.name}`).join(`
|
|
2
2
|
`)}\n\n使用方法:mtb -c <角色ID> <文本内容>`})}function ue(e){e.isLog&&S(c.Logger.DEBUG)}exports.Config=ce,exports.ManosabaTextBoxService=Q,exports.apply=le,Object.defineProperty(exports,`logger`,{enumerable:!0,get:function(){return $}}),exports.name=`manosaba-text-box`;
|
package/lib/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Logger as e,Schema as t,Service as n,h as r}from"koishi";import*as i from"node:fs/promises";import*as a from"node:path";import{createRequire as o}from"node:module";import{fileURLToPath as s}from"node:url";import
|
|
2
|
-
`)}\n\n使用方法:mtb -c <角色ID> <文本内容>`})}function
|
|
1
|
+
import{Logger as e,Schema as t,Service as n,h as r}from"koishi";import*as i from"node:fs/promises";import*as a from"node:path";import{createRequire as o}from"node:module";import{fileURLToPath as s}from"node:url";import{Renderer as c}from"@takumi-rs/wasm/node";import{container as l,image as u,text as d}from"@takumi-rs/helpers";import{webcrypto as f}from"node:crypto";import{cut as p}from"jieba-wasm";import m from"wasm-vips";import*as h from"js-yaml";var g=(e=>typeof require<`u`?require:typeof Proxy<`u`?new Proxy(e,{get:(e,t)=>(typeof require<`u`?require:e)[t]}):e)(function(e){if(typeof require<`u`)return require.apply(this,arguments);throw Error('Calling `require` for "'+e+"\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.")});const _={};let v=-1;function y(e,t=`manosaba-text-box`){let n=_[t]||e.logger(t);return v>=0&&(n.level=v),_[t]=n,n}function b(e){v=e;for(let t in _)_[t].level=e}function x(e){if(e.length<=1)return[...e];let t=[...e],n=new Uint32Array(t.length);f.getRandomValues(n);for(let e=t.length-1;e>0;e--){let r=n[e]%(e+1);[t[e],t[r]]=[t[r],t[e]]}return t}async function S(e){let t=await i.readFile(e,`utf-8`);return h.load(t)}const C=typeof __dirname<`u`?__dirname:a.dirname(s(import.meta.url)),w=typeof __dirname<`u`&&g!==void 0?g:o(import.meta.url);let T=null;const E={debug(e,t){T?.debug(e,t)},info(e,t){T?.info(e,t)},warn(e,t){T?.warn(e,t)},error(e,t){T?.error(e,t)}};function D(e){T=e}const O=global.__manosaba_takumi_state||{initialized:!1,initializing:null,renderer:null};global.__manosaba_takumi_state||(global.__manosaba_takumi_state=O);const k=m({dynamicLibraries:[`vips-heif.wasm`]}).then(e=>(e.concurrency(1),e.Cache.max(0),E.debug(`wasm-vips initialized with AVIF support`),e));let A=null;async function j(){return A||=await k,A}async function M(){if(O.initialized&&O.renderer)return O.renderer;if(O.initializing){if(await O.initializing,!O.renderer)throw Error(`Renderer failed to initialize`);return O.renderer}if(O.initializing=(async()=>{try{let e=w.resolve(`@takumi-rs/wasm/takumi_wasm_bg.wasm`);await i.readFile(e),O.renderer=new c,O.initialized=!0,E.debug(`Takumi WASM initialized successfully`)}catch(e){throw E.error(`Failed to initialize takumi wasm`,{err:e}),O.initializing=null,e}})(),await O.initializing,!O.renderer)throw Error(`Renderer failed to initialize`);return O.renderer}let N=``,P={},F={},I=[];const L=new Map,R=new Map;let z=0;const B=[[728,355],[2500,800]];function V(){return I}async function H(e,t){let n=t||C;N=a.join(n,`assets`);let r=a.join(n,`config`),o=a.join(r,`chara_meta.yml`),s=a.join(r,`text_configs.yml`);try{let[e,t,n]=await Promise.all([S(o),S(s),i.readdir(a.join(N,`background`))]);P=e.mahoshojo||{},F=t.text_configs||{},z=n.filter(e=>e.startsWith(`c`)&&e.endsWith(`.avif`)).length,I=Object.entries(P).map(([e,t])=>({id:e,name:t.full_name})),E.debug(`Loaded character meta and text configs`,{characters:Object.keys(P).length,textConfigs:Object.keys(F).length,backgrounds:z})}catch(e){E.error(`Failed to load config files`,{err:e})}}async function U(e){let t=L.get(e);if(t)return t;let n=await i.readFile(e);return L.set(e,n),n}async function W(e){let t=R.get(e);if(t)return t;let n=await i.readFile(e);return R.size<20&&R.set(e,n),n}async function ee(){if(z===0){let e=a.join(N,`background`);z=(await i.readdir(e)).filter(e=>e.startsWith(`c`)&&e.endsWith(`.avif`)).length}return x(Array.from({length:z},(e,t)=>t+1))[0]}function te(e){let t=P[e];return t?x(Array.from({length:t.emotion_count},(e,t)=>t+1))[0]:1}function G(e){let t=e.charCodeAt(0);return t>=19968&&t<=40959||t>=12352&&t<=12543||t>=65280&&t<=65519||t>=12288&&t<=12351}function ne(e){return/[-—–.,;:!?"'`~()[\]{}<>/\\|]/.test(e)}function K(e,t){return/\s/.test(e)?t*.25:G(e)?t:ne(e)?t*.35:t*.5}function re(e,t){let n=0;for(let r of e)n+=K(r,t);return n}const q=1.2;async function J(e,t,n){let r=Math.max(0,t-12)*.9,i=[],a=e.split(/\n/);for(let e=0;e<a.length;e++){let t=a[e];if(t.trim().length===0){i.push(``);continue}let o=p(t),s=``,c=0;for(let e=0;e<o.length;e++){let t=o[e],a=re(t,n),l=s&&!/^[\s\u3000-\u303f\uff00-\uffef]/.test(t)&&!G(t[0])&&!G(s[s.length-1]),u=l?K(` `,n):0;if(c+u+a<=r)l&&(s+=` `),s+=t,c+=u+a;else if(a>r){s&&(i.push(s),s=``,c=0);let e=``,a=0;for(let o of t){let t=K(o,n);a+t>r?(i.push(e),e=o,a=t):(e+=o,a+=t)}s=e,c=a}else s&&i.push(s),s=t,c=a}s&&i.push(s)}return i.length===0&&e&&i.push(e),i}function Y(e){return{width:e.readUInt32BE(16),height:e.readUInt32BE(20)}}async function X(e){let t=await j(),n=null;try{n=t.Image.newFromBuffer(e);let r=n.writeToBuffer(`.png`,{compression:6});return Buffer.from(r)}catch(e){throw E.error(`Failed to convert AVIF to PNG`,{err:e}),e}finally{if(n)try{n[Symbol.dispose]()}catch{}}}async function ie(e,t,n){let r=await M();try{let i=a.join(N,`background`,`c${t}.avif`),o=a.join(N,`chara`,e,`${e} (${n}).avif`);E.debug(`Loading images`,{backgroundPath:i,characterPath:o});let[s,c]=await Promise.all([W(i),W(o)]);E.debug(`Converting AVIF to PNG for Takumi rendering`);let[f,p]=await Promise.all([X(s),X(c)]),{width:m,height:h}=Y(f);E.debug(`Background image dimensions`,{width:m,height:h}),r.putPersistentImage({src:i,data:new Uint8Array(f)}),r.putPersistentImage({src:o,data:new Uint8Array(p)});let g=l({children:[u({src:i,style:{width:m,height:h}}),u({src:o,style:{position:`absolute`,top:134,left:0}})],style:{position:`relative`,width:m,height:h,display:`block`}});if(F[e]){let t=P[e]?.font||`font3.ttf`,n=await U(a.join(N,`fonts`,t));r.loadFont(n);let s=F[e].filter(e=>e.text).map(e=>{let t=`rgb(${e.font_color.join(`,`)})`;return l({style:{position:`absolute`,left:e.position[0],top:e.position[1]},children:[d(e.text,{fontSize:e.font_size,color:t})]})}),c=l({children:[u({src:i,style:{width:m,height:h}}),u({src:o,style:{position:`absolute`,top:134,left:0}}),...s],style:{position:`relative`,width:m,height:h,display:`block`}}),f=r.render(c,{width:m,height:h,format:`png`});return Buffer.from(f)}let _=r.render(g,{width:m,height:h,format:`png`});return Buffer.from(_)}catch(e){throw E.error(`Failed to generate base image`,{err:e}),e}}async function ae(e,t,n,r,i){E.debug(`drawUserText called`,{text:t,textLength:t.length,initialFontSize:r,fontPath:i,boxRect:n});try{let a=await M(),[[o,s],[c,f]]=n,p=c-o,m=f-s,h=Math.max(0,p-30-10),g=Math.max(0,m-20),_=await U(i);E.debug(`Font file loaded`,{fontPath:i,size:_.length}),a.loadFont(_);let v=r,y=async e=>{let n=await J(t,h,e),r=e*q;return 12+n.length*r<=g},b=40,x=r,S=b;for(;b<=x;){let e=Math.floor((b+x)/2);await y(e)?(S=e,b=e+1):x=e-1}v=S,E.debug(`Auto-adjusted font size`,{originalSize:r,adjustedSize:v,textLength:t.length});let{width:C,height:w}=Y(e),T=`base-image-${Date.now()}-${Math.random()}.png`;a.putPersistentImage({src:T,data:new Uint8Array(e)});let D=o+30,O=s+10,k=await J(t,h,v),A=v*q,j=k.map((e,t)=>l({style:{position:`absolute`,left:0,top:t*A},children:[d(e,{fontSize:v,color:`white`})]})),N=l({children:[u({src:T,style:{width:C,height:w}}),l({children:j,style:{position:`absolute`,left:D,top:O}})],style:{position:`relative`,width:C,height:w,display:`block`}}),P=a.render(N,{width:C,height:w,format:`png`});return E.debug(`Text drawing completed successfully`,{outputSize:P.length}),Buffer.from(P)}catch(t){return E.error(`Failed to draw text`,{err:t}),e}}async function Z(e,t,n,r,i,o){if(!P[t])throw Error(`Unknown character: ${t}`);let s=i??await ee(),c=o??te(t);E.debug(`Generating text box image`,{character:t,backgroundIndex:s,emotionIndex:c,textLength:n.length});let l=await ie(t,s,c),u=P[t]?.font||`font3.ttf`;return await ae(l,n,B,160,a.join(N,`fonts`,u))}var Q=class extends n{constructor(e,t){super(e,`manosaba`,!0),this.config=t}async generateImage(e){let{character:t=this.config.defaultCharacter,text:n,backgroundIndex:r,emotionIndex:i}=e;if(!n||n.trim().length===0)throw Error(`文本内容不能为空`);try{return await Z(this.ctx,t,n,this.config,r,i)}catch(e){throw this.ctx.logger.error(`生成图片失败`,{error:e}),e}}getCharacters(){return V()}};const oe=t.object({defaultCharacter:t.union([`ema`,`hiro`,`sherri`,`hanna`,`nanoka`,`noa`,`miria`,`yuki`,`coco`,`meruru`,`reia`,`warden`,`mago`,`alisa`,`anan`]).default(`ema`).description(`默认使用的角色`),isLog:t.boolean().default(!1).description(`是否输出 debug 日志`)});let $;const se=`manosaba-text-box`;function ce(e,t){$=y(e),le(t),D($),e.on(`ready`,async()=>{await H(e,__dirname)}),e.plugin(Q,t),e.command(`mtb <text:text>`,`生成魔女裁判文本框图片`).option(`character`,`-c <character:string>`,{fallback:t.defaultCharacter}).action(async({session:n,options:i},a)=>{if(!a||a.trim()===``)return`请输入要生成的文本内容`;try{let o=await Z(e,i.character,a,t);await n.send(r.image(o,`image/png`))}catch(e){return $.error(`生成图片失败`,{err:e}),`生成图片失败: ${e.message}`}}),e.command(`mtb.list`,`列出所有可用的角色`).action(()=>{let e=V();return e.length===0?`暂无可用角色`:`可用角色列表:\n${e.map(e=>`${e.id}: ${e.name}`).join(`
|
|
2
|
+
`)}\n\n使用方法:mtb -c <角色ID> <文本内容>`})}function le(t){t.isLog&&b(e.DEBUG)}export{oe as Config,Q as ManosabaTextBoxService,ce as apply,$ as logger,se as name};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-manosaba-text-box",
|
|
3
3
|
"description": "一个自动化表情包生成工具,能够快速生成带有自定义文本的魔法少女的魔女裁判文本框图片",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.15",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
@@ -42,11 +42,11 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@biomejs/biome": "^2.3.14",
|
|
44
44
|
"@types/js-yaml": "^4.0.9",
|
|
45
|
-
"@types/node": "^25.2.
|
|
45
|
+
"@types/node": "^25.2.1",
|
|
46
46
|
"koishi": "^4.18.10",
|
|
47
47
|
"rimraf": "^6.1.2",
|
|
48
48
|
"rolldown": "^1.0.0-rc.3",
|
|
49
|
-
"rolldown-plugin-dts": "^0.
|
|
49
|
+
"rolldown-plugin-dts": "^0.22.1",
|
|
50
50
|
"typescript": "^5.9.3"
|
|
51
51
|
},
|
|
52
52
|
"koishi": {
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@takumi-rs/helpers": "^0.
|
|
64
|
-
"@takumi-rs/wasm": "^0.
|
|
63
|
+
"@takumi-rs/helpers": "^0.67.2",
|
|
64
|
+
"@takumi-rs/wasm": "^0.67.2",
|
|
65
65
|
"entities": "^7.0.1",
|
|
66
66
|
"jieba-wasm": "^2.4.0",
|
|
67
67
|
"js-yaml": "^4.1.1",
|