@drincs/pixi-vn 1.9.0 → 1.9.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/dist/vite.cjs CHANGED
@@ -1,2 +1,4 @@
1
- 'use strict';var fs=require('fs'),path=require('path'),tinyglobby=require('tinyglobby');var z=Object.create;var J=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,Q=Object.prototype.hasOwnProperty;var Z=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports);var q=(n,t,m,f)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Y(t))!Q.call(n,o)&&o!==m&&J(n,o,{get:()=>t[o],enumerable:!(f=U(t,o))||f.enumerable});return n};var tt=(n,t,m)=>(m=n!=null?z(W(n)):{},q(J(m,"default",{value:n,enumerable:true}),n));var X=Z((ht,R)=>{var P=process||{},k=P.argv||[],I=P.env||{},et=!(I.NO_COLOR||k.includes("--no-color"))&&(!!I.FORCE_COLOR||k.includes("--color")||P.platform==="win32"||(P.stdout||{}).isTTY&&I.TERM!=="dumb"||!!I.CI),nt=(n,t,m=n)=>f=>{let o=""+f,l=o.indexOf(t,n.length);return ~l?n+rt(o,t,m,l)+t:n+o+t},rt=(n,t,m,f)=>{let o="",l=0;do o+=n.substring(l,f)+m,l=f+t.length,f=n.indexOf(t,l);while(~f);return o+n.substring(l)},D=(n=et)=>{let t=n?nt:()=>String;return {isColorSupported:n,reset:t("\x1B[0m","\x1B[0m"),bold:t("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:t("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:t("\x1B[3m","\x1B[23m"),underline:t("\x1B[4m","\x1B[24m"),inverse:t("\x1B[7m","\x1B[27m"),hidden:t("\x1B[8m","\x1B[28m"),strikethrough:t("\x1B[9m","\x1B[29m"),black:t("\x1B[30m","\x1B[39m"),red:t("\x1B[31m","\x1B[39m"),green:t("\x1B[32m","\x1B[39m"),yellow:t("\x1B[33m","\x1B[39m"),blue:t("\x1B[34m","\x1B[39m"),magenta:t("\x1B[35m","\x1B[39m"),cyan:t("\x1B[36m","\x1B[39m"),white:t("\x1B[37m","\x1B[39m"),gray:t("\x1B[90m","\x1B[39m"),bgBlack:t("\x1B[40m","\x1B[49m"),bgRed:t("\x1B[41m","\x1B[49m"),bgGreen:t("\x1B[42m","\x1B[49m"),bgYellow:t("\x1B[43m","\x1B[49m"),bgBlue:t("\x1B[44m","\x1B[49m"),bgMagenta:t("\x1B[45m","\x1B[49m"),bgCyan:t("\x1B[46m","\x1B[49m"),bgWhite:t("\x1B[47m","\x1B[49m"),blackBright:t("\x1B[90m","\x1B[39m"),redBright:t("\x1B[91m","\x1B[39m"),greenBright:t("\x1B[92m","\x1B[39m"),yellowBright:t("\x1B[93m","\x1B[39m"),blueBright:t("\x1B[94m","\x1B[39m"),magentaBright:t("\x1B[95m","\x1B[39m"),cyanBright:t("\x1B[96m","\x1B[39m"),whiteBright:t("\x1B[97m","\x1B[39m"),bgBlackBright:t("\x1B[100m","\x1B[49m"),bgRedBright:t("\x1B[101m","\x1B[49m"),bgGreenBright:t("\x1B[102m","\x1B[49m"),bgYellowBright:t("\x1B[103m","\x1B[49m"),bgBlueBright:t("\x1B[104m","\x1B[49m"),bgMagentaBright:t("\x1B[105m","\x1B[49m"),bgCyanBright:t("\x1B[106m","\x1B[49m"),bgWhiteBright:t("\x1B[107m","\x1B[49m")}};R.exports=D();R.exports.createColors=D;});var O="/__pixi-vn/characters",C="/__pixi-vn/labels",N="/__pixi-vn/assets/manifest",M="/__pixi-vn/canvas-options";var V=tt(X());var v=V.default.cyan("(pixi-vn)");function x(n){return n?Array.isArray(n)?n:[n]:[]}function mt(n){return n?n.bundles.map(t=>t.name):[]}function ft(n){if(!n)return [];let t=new Set;for(let m of n.bundles){let f=m.assets;if(Array.isArray(f))for(let o of f){let l=o.alias;if(l)for(let g of Array.isArray(l)?l:[l])t.add(g);}else if(f&&typeof f=="object")for(let o of Object.keys(f))t.add(o);}return Array.from(t)}function ut(n){let t=[],m=[];for(let f of n)try{let o=fs.readFileSync(f,"utf-8"),l=/newLabel\(\s*["']([^"']+)["']/g,g;for(;(g=l.exec(o))!==null;)m.push(g[1]);let h=/new\s+\w*[Cc]haracter\(\s*["']([^"']+)["']/g;for(;(g=h.exec(o))!==null;)t.push(g[1]);}catch{}return {charIds:t,labelIds:m}}function dt(n){let t,m,f=new Promise(e=>{m=e;}),o=[...x(n?.content),...x(n?.characters),...x(n?.labels)],l=[],g=[],h=new Set,F=[],S=typeof n?.assetsManifest=="function",y=typeof n?.assetsManifest=="function"?void 0:n?.assetsManifest;async function w(e){if(typeof n?.assetsManifest=="function")try{let r=await n.assetsManifest(e);y=r,p.manifest=r??null;}catch(r){t?.logger.error(`${v} Failed to resolve the assets manifest.`,{error:r instanceof Error?r:new Error(String(r)),timestamp:true});}}let E=new Map;function L(){if(!n?.typeFilePath||!t)return null;let e=n.typeFilePath;return path.isAbsolute(e)?e:path.resolve(t.root,e)}function B(){let e=[...g,...Array.from(E.values()).flat()];return Array.from(new Set(e))}function G(e,r,s,i,d){fs.mkdirSync(path.dirname(e),{recursive:true});let a=["/* eslint-disable */","// noinspection JSUnusedGlobalSymbols","// This file is auto-generated by @drincs/pixi-vn vite plugin. Do not edit manually."];if(r.length>0){a.push('declare module "@drincs/pixi-vn/characters" {'),a.push(" interface PixivnCharacterIds {");for(let c of r)a.push(` ${JSON.stringify(c)}: never;`);a.push(" }"),a.push("}");}if(s.length>0){a.push('declare module "@drincs/pixi-vn/narration" {'),a.push(" interface PixivnLabelIds {");for(let c of s)a.push(` ${JSON.stringify(c)}: never;`);a.push(" }"),a.push("}");}if(i.length>0||d.length>0){if(a.push('declare module "@drincs/pixi-vn/canvas" {'),i.length>0){a.push(" interface PixivnBundleIds {");for(let c of i)a.push(` ${JSON.stringify(c)}: never;`);a.push(" }");}if(d.length>0){a.push(" interface PixivnAssetAliasIds {");for(let c of d)a.push(` ${JSON.stringify(c)}: never;`);a.push(" }");}a.push("}");}a.push(`export const characterIds = ${JSON.stringify(r)} as const;`);{let c=Object.fromEntries(r.map(u=>[u,u]));a.push(`export const characterIdsEnum = ${JSON.stringify(c)} as const;`);}a.push(`export const labelIds = ${JSON.stringify(s)} as const;`);{let c=Object.fromEntries(s.map(u=>[u,u]));a.push(`export const labelIdsEnum = ${JSON.stringify(c)} as const;`);}a.push(`export const bundleIds = ${JSON.stringify(i)} as const;`);{let c=Object.fromEntries(i.map(u=>[u,u]));a.push(`export const bundleIdsEnum = ${JSON.stringify(c)} as const;`);}a.push(`export const assetAliasIds = ${JSON.stringify(d)} as const;`);{let c=Object.fromEntries(d.map(u=>[u,u]));a.push(`export const assetAliasIdsEnum = ${JSON.stringify(c)} as const;`);}a.push(""),fs.writeFileSync(e,a.join(`
2
- `),"utf-8");}function H(){p.characters=l,p.labels=B();}function b(){H();let e=L();if(e)try{G(e,l.map(r=>r.id),B(),mt(y),ft(y));}catch(r){t?.logger.error(`${v} Failed to write keys file "${e}".`,{error:r instanceof Error?r:new Error(String(r)),timestamp:true});}}async function _(e,r=[]){try{l=(await e("@drincs/pixi-vn/characters")).RegisteredCharacters?.values()??[];}catch{l=[];}try{g=(await e("@drincs/pixi-vn/narration")).RegisteredLabels?.keys()??[];}catch{g=[];}if(r.length>0){let{charIds:i,labelIds:d}=ut(r),a=new Set(l.map(u=>u.id)),c=new Set(g);for(let u of i)a.has(u)||l.push({id:u});for(let u of d)c.has(u)||g.push(u);}let s=l.map(i=>i.id).join(", ")||"none";t?.logger.info(`${v} ${V.default.dim(`${l.length} character(s): [${s}], ${g.length} label(s)`)}`,{timestamp:true});}async function $(e,r){let s=[],i=[...x(n?.characters),...x(n?.labels)],d=await tinyglobby.glob(i,{cwd:r,absolute:true,onlyFiles:true});for(let c of d){h.add(c);try{await e(c);}catch{s.push(c);}}await _(e,s),b();let a=await tinyglobby.glob(x(n?.content),{cwd:r,absolute:true,onlyFiles:true});for(let c of a){h.add(c);try{await e(c);}catch{s.push(c);}}return s}async function T(e,r){try{await e("@drincs/pixi-vn/characters");}catch{}try{await e("@drincs/pixi-vn/narration");}catch{}let s=await $(e,r);await _(e,s),await w(e),b(),m();}async function K(e){for(let s of h)for(let i of e.moduleGraph.getModulesByFile(s)??[])e.moduleGraph.invalidateModule(i);try{(await e.ssrLoadModule("@drincs/pixi-vn/characters")).RegisteredCharacters?.clear?.();}catch{}try{(await e.ssrLoadModule("@drincs/pixi-vn/narration")).RegisteredLabels?.clear?.();}catch{}let r=await $(s=>e.ssrLoadModule(s),t.root);await _(s=>e.ssrLoadModule(s),r),await w(s=>e.ssrLoadModule(s)),b();for(let s of F)s();}let p={characters:null,labels:null,manifest:y??null,canvasOptions:null};function A(e,r){return (s,i)=>{if(i.setHeader("Content-Type","application/json"),s.method==="GET"){let d=p[e];if(d===null){i.statusCode=404,i.end(JSON.stringify({error:`${r} not initialized`}));return}i.statusCode=200,i.end(JSON.stringify(d));return}if(s.method==="POST"){let d="";s.on("data",a=>{d+=a.toString();}),s.on("end",()=>{try{p[e]=JSON.parse(d),i.statusCode=201,i.end(JSON.stringify({message:`${r} updated successfully`}));}catch{i.statusCode=400,i.end(JSON.stringify({error:`Invalid JSON format for ${r}`}));}});}}}return {name:"vite-plugin-pixi-vn",enforce:"pre",api:{contentLoaded:f,get characters(){return l},onReload(e){F.push(e);},setExternalLabels(e,r){E.set(e,r),b();},clearExternalLabels(e){E.delete(e),b();},setAssetsManifest(e){y=e,p.manifest=e,b();}},config(e,r){if(r.command==="serve"&&o.length>0)return {ssr:{noExternal:["@drincs/pixi-vn"]}}},configResolved(e){t=e,o.length===0&&!S&&(b(),m());},async buildStart(){if(t?.command!=="build"||o.length===0&&!S)return;let{createServer:e}=await import('vite'),r=await e({root:t.root,configFile:false,resolve:t.resolve,server:{middlewareMode:true},appType:"custom",logLevel:"silent",optimizeDeps:{noDiscovery:true},ssr:{noExternal:["@drincs/pixi-vn"]}});try{await T(s=>r.ssrLoadModule(s),t.root);}catch{m();}finally{await r.close();}},configureServer(e){(o.length>0||S)&&T(r=>e.ssrLoadModule(r),t.root).catch(()=>{m();}),e.middlewares.use(O,A("characters","Characters")),e.middlewares.use(C,A("labels","Labels")),e.middlewares.use(N,A("manifest","Manifest")),e.middlewares.use(M,A("canvasOptions","Canvas options"));},async hotUpdate({file:e,server:r}){let s=L();if(s&&e===s)return [];if(o.length>0&&h.has(e)){try{await K(r);}catch(i){t?.logger.error(`${v} Failed to reload content.`,{error:i instanceof Error?i:new Error(String(i)),timestamp:true});}return []}if(S)try{await w(i=>r.ssrLoadModule(i)),b();}catch(i){t?.logger.error(`${v} Failed to refresh the assets manifest.`,{error:i instanceof Error?i:new Error(String(i)),timestamp:true});}}}}exports.PIXIVN_DEV_API_ASSETS_MANIFEST=N;exports.PIXIVN_DEV_API_CANVAS_OPTIONS=M;exports.PIXIVN_DEV_API_CHARACTERS=O;exports.PIXIVN_DEV_API_LABELS=C;exports.vitePluginPixivn=dt;
1
+ 'use strict';var fs=require('fs'),path=require('path'),tinyglobby=require('tinyglobby');var Q=Object.create;var k=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var tt=Object.getPrototypeOf,et=Object.prototype.hasOwnProperty;var nt=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports);var rt=(n,t,d,m)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of q(t))!et.call(n,o)&&o!==d&&k(n,o,{get:()=>t[o],enumerable:!(m=Z(t,o))||m.enumerable});return n};var st=(n,t,d)=>(d=n!=null?Q(tt(n)):{},rt(k(d,"default",{value:n,enumerable:true}),n));var G=nt((vt,M)=>{var w=process||{},X=w.argv||[],A=w.env||{},it=!(A.NO_COLOR||X.includes("--no-color"))&&(!!A.FORCE_COLOR||X.includes("--color")||w.platform==="win32"||(w.stdout||{}).isTTY&&A.TERM!=="dumb"||!!A.CI),at=(n,t,d=n)=>m=>{let o=""+m,l=o.indexOf(t,n.length);return ~l?n+ot(o,t,d,l)+t:n+o+t},ot=(n,t,d,m)=>{let o="",l=0;do o+=n.substring(l,m)+d,l=m+t.length,m=n.indexOf(t,l);while(~m);return o+n.substring(l)},j=(n=it)=>{let t=n?at:()=>String;return {isColorSupported:n,reset:t("\x1B[0m","\x1B[0m"),bold:t("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:t("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:t("\x1B[3m","\x1B[23m"),underline:t("\x1B[4m","\x1B[24m"),inverse:t("\x1B[7m","\x1B[27m"),hidden:t("\x1B[8m","\x1B[28m"),strikethrough:t("\x1B[9m","\x1B[29m"),black:t("\x1B[30m","\x1B[39m"),red:t("\x1B[31m","\x1B[39m"),green:t("\x1B[32m","\x1B[39m"),yellow:t("\x1B[33m","\x1B[39m"),blue:t("\x1B[34m","\x1B[39m"),magenta:t("\x1B[35m","\x1B[39m"),cyan:t("\x1B[36m","\x1B[39m"),white:t("\x1B[37m","\x1B[39m"),gray:t("\x1B[90m","\x1B[39m"),bgBlack:t("\x1B[40m","\x1B[49m"),bgRed:t("\x1B[41m","\x1B[49m"),bgGreen:t("\x1B[42m","\x1B[49m"),bgYellow:t("\x1B[43m","\x1B[49m"),bgBlue:t("\x1B[44m","\x1B[49m"),bgMagenta:t("\x1B[45m","\x1B[49m"),bgCyan:t("\x1B[46m","\x1B[49m"),bgWhite:t("\x1B[47m","\x1B[49m"),blackBright:t("\x1B[90m","\x1B[39m"),redBright:t("\x1B[91m","\x1B[39m"),greenBright:t("\x1B[92m","\x1B[39m"),yellowBright:t("\x1B[93m","\x1B[39m"),blueBright:t("\x1B[94m","\x1B[39m"),magentaBright:t("\x1B[95m","\x1B[39m"),cyanBright:t("\x1B[96m","\x1B[39m"),whiteBright:t("\x1B[97m","\x1B[39m"),bgBlackBright:t("\x1B[100m","\x1B[49m"),bgRedBright:t("\x1B[101m","\x1B[49m"),bgGreenBright:t("\x1B[102m","\x1B[49m"),bgYellowBright:t("\x1B[103m","\x1B[49m"),bgBlueBright:t("\x1B[104m","\x1B[49m"),bgMagentaBright:t("\x1B[105m","\x1B[49m"),bgCyanBright:t("\x1B[106m","\x1B[49m"),bgWhiteBright:t("\x1B[107m","\x1B[49m")}};M.exports=j();M.exports.createColors=j;});var O="/__pixi-vn/characters",C="/__pixi-vn/labels",N="/__pixi-vn/assets/manifest",V="/__pixi-vn/canvas-options";var L=st(G());var v=L.default.cyan("(pixi-vn)"),R="virtual:pixi-vn-testing",H=`\0${R}`;function x(n){return n?Array.isArray(n)?n:[n]:[]}function gt(n){return n?n.bundles.map(t=>t.name):[]}function bt(n){if(!n)return [];let t=new Set;for(let d of n.bundles){let m=d.assets;if(Array.isArray(m))for(let o of m){let l=o.alias;if(l)for(let g of Array.isArray(l)?l:[l])t.add(g);}else if(m&&typeof m=="object")for(let o of Object.keys(m))t.add(o);}return Array.from(t)}function pt(n){let t=[],d=[];for(let m of n)try{let o=fs.readFileSync(m,"utf-8"),l=/newLabel\(\s*["']([^"']+)["']/g,g;for(;(g=l.exec(o))!==null;)d.push(g[1]);let p=/new\s+\w*[Cc]haracter\(\s*["']([^"']+)["']/g;for(;(g=p.exec(o))!==null;)t.push(g[1]);}catch{}return {charIds:t,labelIds:d}}function ht(n){let t,d,m=new Promise(e=>{d=e;}),o=[...x(n?.content),...x(n?.characters),...x(n?.labels)],l=[],g=[],p=new Set,F=[],I=typeof n?.assetsManifest=="function",U=n?.testing===false,T=typeof n?.testing=="object"?n.testing.windowKey:void 0,y=typeof n?.assetsManifest=="function"?void 0:n?.assetsManifest;async function P(e){if(typeof n?.assetsManifest=="function")try{let r=await n.assetsManifest(e);y=r,h.manifest=r??null;}catch(r){t?.logger.error(`${v} Failed to resolve the assets manifest.`,{error:r instanceof Error?r:new Error(String(r)),timestamp:true});}}let _=new Map;function $(){if(!n?.typeFilePath||!t)return null;let e=n.typeFilePath;return path.isAbsolute(e)?e:path.resolve(t.root,e)}function B(){let e=[...g,...Array.from(_.values()).flat()];return Array.from(new Set(e))}function z(e,r,s,i,u){fs.mkdirSync(path.dirname(e),{recursive:true});let a=["/* eslint-disable */","// noinspection JSUnusedGlobalSymbols","// This file is auto-generated by @drincs/pixi-vn vite plugin. Do not edit manually."];if(r.length>0){a.push('declare module "@drincs/pixi-vn/characters" {'),a.push(" interface PixivnCharacterIds {");for(let c of r)a.push(` ${JSON.stringify(c)}: never;`);a.push(" }"),a.push("}");}if(s.length>0){a.push('declare module "@drincs/pixi-vn/narration" {'),a.push(" interface PixivnLabelIds {");for(let c of s)a.push(` ${JSON.stringify(c)}: never;`);a.push(" }"),a.push("}");}if(i.length>0||u.length>0){if(a.push('declare module "@drincs/pixi-vn/canvas" {'),i.length>0){a.push(" interface PixivnBundleIds {");for(let c of i)a.push(` ${JSON.stringify(c)}: never;`);a.push(" }");}if(u.length>0){a.push(" interface PixivnAssetAliasIds {");for(let c of u)a.push(` ${JSON.stringify(c)}: never;`);a.push(" }");}a.push("}");}a.push(`export const characterIds = ${JSON.stringify(r)} as const;`);{let c=Object.fromEntries(r.map(f=>[f,f]));a.push(`export const characterIdsEnum = ${JSON.stringify(c)} as const;`);}a.push(`export const labelIds = ${JSON.stringify(s)} as const;`);{let c=Object.fromEntries(s.map(f=>[f,f]));a.push(`export const labelIdsEnum = ${JSON.stringify(c)} as const;`);}a.push(`export const bundleIds = ${JSON.stringify(i)} as const;`);{let c=Object.fromEntries(i.map(f=>[f,f]));a.push(`export const bundleIdsEnum = ${JSON.stringify(c)} as const;`);}a.push(`export const assetAliasIds = ${JSON.stringify(u)} as const;`);{let c=Object.fromEntries(u.map(f=>[f,f]));a.push(`export const assetAliasIdsEnum = ${JSON.stringify(c)} as const;`);}a.push(""),fs.writeFileSync(e,a.join(`
2
+ `),"utf-8");}function W(){h.characters=l,h.labels=B();}function b(){W();let e=$();if(e)try{z(e,l.map(r=>r.id),B(),gt(y),bt(y));}catch(r){t?.logger.error(`${v} Failed to write keys file "${e}".`,{error:r instanceof Error?r:new Error(String(r)),timestamp:true});}}async function E(e,r=[]){try{l=(await e("@drincs/pixi-vn/characters")).RegisteredCharacters?.values()??[];}catch{l=[];}try{g=(await e("@drincs/pixi-vn/narration")).RegisteredLabels?.keys()??[];}catch{g=[];}if(r.length>0){let{charIds:i,labelIds:u}=pt(r),a=new Set(l.map(f=>f.id)),c=new Set(g);for(let f of i)a.has(f)||l.push({id:f});for(let f of u)c.has(f)||g.push(f);}let s=l.map(i=>i.id).join(", ")||"none";t?.logger.info(`${v} ${L.default.dim(`${l.length} character(s): [${s}], ${g.length} label(s)`)}`,{timestamp:true});}async function D(e,r){let s=[],i=[...x(n?.characters),...x(n?.labels)],u=await tinyglobby.glob(i,{cwd:r,absolute:true,onlyFiles:true});for(let c of u){p.add(c);try{await e(c);}catch{s.push(c);}}await E(e,s),b();let a=await tinyglobby.glob(x(n?.content),{cwd:r,absolute:true,onlyFiles:true});for(let c of a){p.add(c);try{await e(c);}catch{s.push(c);}}return s}async function J(e,r){try{await e("@drincs/pixi-vn/characters");}catch{}try{await e("@drincs/pixi-vn/narration");}catch{}let s=await D(e,r);await E(e,s),await P(e),b(),d();}async function Y(e){for(let s of p)for(let i of e.moduleGraph.getModulesByFile(s)??[])e.moduleGraph.invalidateModule(i);try{(await e.ssrLoadModule("@drincs/pixi-vn/characters")).RegisteredCharacters?.clear?.();}catch{}try{(await e.ssrLoadModule("@drincs/pixi-vn/narration")).RegisteredLabels?.clear?.();}catch{}let r=await D(s=>e.ssrLoadModule(s),t.root);await E(s=>e.ssrLoadModule(s),r),await P(s=>e.ssrLoadModule(s)),b();for(let s of F)s();}let h={characters:null,labels:null,manifest:y??null,canvasOptions:null};function S(e,r){return (s,i)=>{if(i.setHeader("Content-Type","application/json"),s.method==="GET"){let u=h[e];if(u===null){i.statusCode=404,i.end(JSON.stringify({error:`${r} not initialized`}));return}i.statusCode=200,i.end(JSON.stringify(u));return}if(s.method==="POST"){let u="";s.on("data",a=>{u+=a.toString();}),s.on("end",()=>{try{h[e]=JSON.parse(u),i.statusCode=201,i.end(JSON.stringify({message:`${r} updated successfully`}));}catch{i.statusCode=400,i.end(JSON.stringify({error:`Invalid JSON format for ${r}`}));}});}}}return {name:"vite-plugin-pixi-vn",enforce:"pre",api:{contentLoaded:m,get characters(){return l},onReload(e){F.push(e);},setExternalLabels(e,r){_.set(e,r),b();},clearExternalLabels(e){_.delete(e),b();},setAssetsManifest(e){y=e,h.manifest=e,b();}},resolveId(e){if(e===R)return H},load(e){if(e===H)return `import { Game } from "@drincs/pixi-vn";
3
+ Game.testing.enable(${T?JSON.stringify({windowKey:T}):""});
4
+ `},transformIndexHtml(){if(!(U||t?.command!=="serve"))return [{tag:"script",attrs:{type:"module",src:`/@id/${R}`},injectTo:"head-prepend"}]},config(e,r){if(r.command==="serve"&&o.length>0)return {ssr:{noExternal:["@drincs/pixi-vn"]}}},configResolved(e){t=e,o.length===0&&!I&&(b(),d());},async buildStart(){if(t?.command!=="build"||o.length===0&&!I)return;let{createServer:e}=await import('vite'),r=await e({root:t.root,configFile:false,resolve:t.resolve,server:{middlewareMode:true},appType:"custom",logLevel:"silent",optimizeDeps:{noDiscovery:true},ssr:{noExternal:["@drincs/pixi-vn"]}});try{await J(s=>r.ssrLoadModule(s),t.root);}catch{d();}finally{await r.close();}},configureServer(e){(o.length>0||I)&&J(r=>e.ssrLoadModule(r),t.root).catch(()=>{d();}),e.middlewares.use(O,S("characters","Characters")),e.middlewares.use(C,S("labels","Labels")),e.middlewares.use(N,S("manifest","Manifest")),e.middlewares.use(V,S("canvasOptions","Canvas options"));},async hotUpdate({file:e,server:r}){let s=$();if(s&&e===s)return [];if(o.length>0&&p.has(e)){try{await Y(r);}catch(i){t?.logger.error(`${v} Failed to reload content.`,{error:i instanceof Error?i:new Error(String(i)),timestamp:true});}return []}if(I)try{await P(i=>r.ssrLoadModule(i)),b();}catch(i){t?.logger.error(`${v} Failed to refresh the assets manifest.`,{error:i instanceof Error?i:new Error(String(i)),timestamp:true});}}}}exports.PIXIVN_DEV_API_ASSETS_MANIFEST=N;exports.PIXIVN_DEV_API_CANVAS_OPTIONS=V;exports.PIXIVN_DEV_API_CHARACTERS=O;exports.PIXIVN_DEV_API_LABELS=C;exports.vitePluginPixivn=ht;
package/dist/vite.d.cts CHANGED
@@ -138,6 +138,25 @@ interface VitePluginPixivnOptions {
138
138
  * ```
139
139
  */
140
140
  assetsManifest?: AssetsManifestOption;
141
+ /**
142
+ * Auto-enables `Game.testing` (see the `pixi-vn-testing` skill) for as long as the dev server
143
+ * keeps running, by injecting a small module into `index.html` that calls
144
+ * `Game.testing.enable(...)` on page load — no app code required for this part. **Never
145
+ * injected during `vite build`**, regardless of this option.
146
+ *
147
+ * This only turns the `window` bridge on/off. Every action it exposes still needs the app's
148
+ * real `StepLabelProps` (`navigate`/`t`/`toast`/etc.) to work — the app must separately call
149
+ * `Game.testing.setProps(props)` wherever it already builds those props (e.g. the end of a
150
+ * `useGameProps()`-style hook), unconditionally, since `setProps` is cheap and safe to call
151
+ * whether or not testing happens to be enabled.
152
+ *
153
+ * Pass `false` to opt out entirely (e.g. a shared dev server you don't want remote-controllable).
154
+ * @default true
155
+ */
156
+ testing?: boolean | {
157
+ /** The `window` property the testing API is attached under. @default "pixiVN" */
158
+ windowKey?: string;
159
+ };
141
160
  }
142
161
  /**
143
162
  * Creates a Vite plugin for Pixi'VN integration.
package/dist/vite.d.ts CHANGED
@@ -138,6 +138,25 @@ interface VitePluginPixivnOptions {
138
138
  * ```
139
139
  */
140
140
  assetsManifest?: AssetsManifestOption;
141
+ /**
142
+ * Auto-enables `Game.testing` (see the `pixi-vn-testing` skill) for as long as the dev server
143
+ * keeps running, by injecting a small module into `index.html` that calls
144
+ * `Game.testing.enable(...)` on page load — no app code required for this part. **Never
145
+ * injected during `vite build`**, regardless of this option.
146
+ *
147
+ * This only turns the `window` bridge on/off. Every action it exposes still needs the app's
148
+ * real `StepLabelProps` (`navigate`/`t`/`toast`/etc.) to work — the app must separately call
149
+ * `Game.testing.setProps(props)` wherever it already builds those props (e.g. the end of a
150
+ * `useGameProps()`-style hook), unconditionally, since `setProps` is cheap and safe to call
151
+ * whether or not testing happens to be enabled.
152
+ *
153
+ * Pass `false` to opt out entirely (e.g. a shared dev server you don't want remote-controllable).
154
+ * @default true
155
+ */
156
+ testing?: boolean | {
157
+ /** The `window` property the testing API is attached under. @default "pixiVN" */
158
+ windowKey?: string;
159
+ };
141
160
  }
142
161
  /**
143
162
  * Creates a Vite plugin for Pixi'VN integration.
package/dist/vite.mjs CHANGED
@@ -1,2 +1,4 @@
1
- import {a as a$1,b,c as c$1,d}from'./chunk-3BBZHKU4.mjs';export{c as PIXIVN_DEV_API_ASSETS_MANIFEST,d as PIXIVN_DEV_API_CANVAS_OPTIONS,a as PIXIVN_DEV_API_CHARACTERS,b as PIXIVN_DEV_API_LABELS}from'./chunk-3BBZHKU4.mjs';import {a,c}from'./chunk-K7JIC2F2.mjs';import {mkdirSync,writeFileSync,readFileSync}from'fs';import {isAbsolute,resolve,dirname}from'path';import {glob}from'tinyglobby';var D=a((ot,R)=>{var A=process||{},k=A.argv||[],P=A.env||{},U=!(P.NO_COLOR||k.includes("--no-color"))&&(!!P.FORCE_COLOR||k.includes("--color")||A.platform==="win32"||(A.stdout||{}).isTTY&&P.TERM!=="dumb"||!!P.CI),Y=(n,t,d=n)=>f=>{let l=""+f,c=l.indexOf(t,n.length);return ~c?n+W(l,t,d,c)+t:n+l+t},W=(n,t,d,f)=>{let l="",c=0;do l+=n.substring(c,f)+d,c=f+t.length,f=n.indexOf(t,c);while(~f);return l+n.substring(c)},T=(n=U)=>{let t=n?Y:()=>String;return {isColorSupported:n,reset:t("\x1B[0m","\x1B[0m"),bold:t("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:t("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:t("\x1B[3m","\x1B[23m"),underline:t("\x1B[4m","\x1B[24m"),inverse:t("\x1B[7m","\x1B[27m"),hidden:t("\x1B[8m","\x1B[28m"),strikethrough:t("\x1B[9m","\x1B[29m"),black:t("\x1B[30m","\x1B[39m"),red:t("\x1B[31m","\x1B[39m"),green:t("\x1B[32m","\x1B[39m"),yellow:t("\x1B[33m","\x1B[39m"),blue:t("\x1B[34m","\x1B[39m"),magenta:t("\x1B[35m","\x1B[39m"),cyan:t("\x1B[36m","\x1B[39m"),white:t("\x1B[37m","\x1B[39m"),gray:t("\x1B[90m","\x1B[39m"),bgBlack:t("\x1B[40m","\x1B[49m"),bgRed:t("\x1B[41m","\x1B[49m"),bgGreen:t("\x1B[42m","\x1B[49m"),bgYellow:t("\x1B[43m","\x1B[49m"),bgBlue:t("\x1B[44m","\x1B[49m"),bgMagenta:t("\x1B[45m","\x1B[49m"),bgCyan:t("\x1B[46m","\x1B[49m"),bgWhite:t("\x1B[47m","\x1B[49m"),blackBright:t("\x1B[90m","\x1B[39m"),redBright:t("\x1B[91m","\x1B[39m"),greenBright:t("\x1B[92m","\x1B[39m"),yellowBright:t("\x1B[93m","\x1B[39m"),blueBright:t("\x1B[94m","\x1B[39m"),magentaBright:t("\x1B[95m","\x1B[39m"),cyanBright:t("\x1B[96m","\x1B[39m"),whiteBright:t("\x1B[97m","\x1B[39m"),bgBlackBright:t("\x1B[100m","\x1B[49m"),bgRedBright:t("\x1B[101m","\x1B[49m"),bgGreenBright:t("\x1B[102m","\x1B[49m"),bgYellowBright:t("\x1B[103m","\x1B[49m"),bgBlueBright:t("\x1B[104m","\x1B[49m"),bgMagentaBright:t("\x1B[105m","\x1B[49m"),bgCyanBright:t("\x1B[106m","\x1B[49m"),bgWhiteBright:t("\x1B[107m","\x1B[49m")}};R.exports=T();R.exports.createColors=T;});var F=c(D(),1);var v=F.default.cyan("(pixi-vn)");function x(n){return n?Array.isArray(n)?n:[n]:[]}function nt(n){return n?n.bundles.map(t=>t.name):[]}function st(n){if(!n)return [];let t=new Set;for(let d of n.bundles){let f=d.assets;if(Array.isArray(f))for(let l of f){let c=l.alias;if(c)for(let g of Array.isArray(c)?c:[c])t.add(g);}else if(f&&typeof f=="object")for(let l of Object.keys(f))t.add(l);}return Array.from(t)}function it(n){let t=[],d=[];for(let f of n)try{let l=readFileSync(f,"utf-8"),c=/newLabel\(\s*["']([^"']+)["']/g,g;for(;(g=c.exec(l))!==null;)d.push(g[1]);let h=/new\s+\w*[Cc]haracter\(\s*["']([^"']+)["']/g;for(;(g=h.exec(l))!==null;)t.push(g[1]);}catch{}return {charIds:t,labelIds:d}}function at(n){let t,d$1,f=new Promise(e=>{d$1=e;}),l=[...x(n?.content),...x(n?.characters),...x(n?.labels)],c=[],g=[],h=new Set,B=[],S=typeof n?.assetsManifest=="function",y=typeof n?.assetsManifest=="function"?void 0:n?.assetsManifest;async function I(e){if(typeof n?.assetsManifest=="function")try{let r=await n.assetsManifest(e);y=r,p.manifest=r??null;}catch(r){t?.logger.error(`${v} Failed to resolve the assets manifest.`,{error:r instanceof Error?r:new Error(String(r)),timestamp:true});}}let E=new Map;function L(){if(!n?.typeFilePath||!t)return null;let e=n.typeFilePath;return isAbsolute(e)?e:resolve(t.root,e)}function $(){let e=[...g,...Array.from(E.values()).flat()];return Array.from(new Set(e))}function X(e,r,s,i,u){mkdirSync(dirname(e),{recursive:true});let a=["/* eslint-disable */","// noinspection JSUnusedGlobalSymbols","// This file is auto-generated by @drincs/pixi-vn vite plugin. Do not edit manually."];if(r.length>0){a.push('declare module "@drincs/pixi-vn/characters" {'),a.push(" interface PixivnCharacterIds {");for(let o of r)a.push(` ${JSON.stringify(o)}: never;`);a.push(" }"),a.push("}");}if(s.length>0){a.push('declare module "@drincs/pixi-vn/narration" {'),a.push(" interface PixivnLabelIds {");for(let o of s)a.push(` ${JSON.stringify(o)}: never;`);a.push(" }"),a.push("}");}if(i.length>0||u.length>0){if(a.push('declare module "@drincs/pixi-vn/canvas" {'),i.length>0){a.push(" interface PixivnBundleIds {");for(let o of i)a.push(` ${JSON.stringify(o)}: never;`);a.push(" }");}if(u.length>0){a.push(" interface PixivnAssetAliasIds {");for(let o of u)a.push(` ${JSON.stringify(o)}: never;`);a.push(" }");}a.push("}");}a.push(`export const characterIds = ${JSON.stringify(r)} as const;`);{let o=Object.fromEntries(r.map(m=>[m,m]));a.push(`export const characterIdsEnum = ${JSON.stringify(o)} as const;`);}a.push(`export const labelIds = ${JSON.stringify(s)} as const;`);{let o=Object.fromEntries(s.map(m=>[m,m]));a.push(`export const labelIdsEnum = ${JSON.stringify(o)} as const;`);}a.push(`export const bundleIds = ${JSON.stringify(i)} as const;`);{let o=Object.fromEntries(i.map(m=>[m,m]));a.push(`export const bundleIdsEnum = ${JSON.stringify(o)} as const;`);}a.push(`export const assetAliasIds = ${JSON.stringify(u)} as const;`);{let o=Object.fromEntries(u.map(m=>[m,m]));a.push(`export const assetAliasIdsEnum = ${JSON.stringify(o)} as const;`);}a.push(""),writeFileSync(e,a.join(`
2
- `),"utf-8");}function G(){p.characters=c,p.labels=$();}function b$1(){G();let e=L();if(e)try{X(e,c.map(r=>r.id),$(),nt(y),st(y));}catch(r){t?.logger.error(`${v} Failed to write keys file "${e}".`,{error:r instanceof Error?r:new Error(String(r)),timestamp:true});}}async function O(e,r=[]){try{c=(await e("@drincs/pixi-vn/characters")).RegisteredCharacters?.values()??[];}catch{c=[];}try{g=(await e("@drincs/pixi-vn/narration")).RegisteredLabels?.keys()??[];}catch{g=[];}if(r.length>0){let{charIds:i,labelIds:u}=it(r),a=new Set(c.map(m=>m.id)),o=new Set(g);for(let m of i)a.has(m)||c.push({id:m});for(let m of u)o.has(m)||g.push(m);}let s=c.map(i=>i.id).join(", ")||"none";t?.logger.info(`${v} ${F.default.dim(`${c.length} character(s): [${s}], ${g.length} label(s)`)}`,{timestamp:true});}async function V(e,r){let s=[],i=[...x(n?.characters),...x(n?.labels)],u=await glob(i,{cwd:r,absolute:true,onlyFiles:true});for(let o of u){h.add(o);try{await e(o);}catch{s.push(o);}}await O(e,s),b$1();let a=await glob(x(n?.content),{cwd:r,absolute:true,onlyFiles:true});for(let o of a){h.add(o);try{await e(o);}catch{s.push(o);}}return s}async function J(e,r){try{await e("@drincs/pixi-vn/characters");}catch{}try{await e("@drincs/pixi-vn/narration");}catch{}let s=await V(e,r);await O(e,s),await I(e),b$1(),d$1();}async function H(e){for(let s of h)for(let i of e.moduleGraph.getModulesByFile(s)??[])e.moduleGraph.invalidateModule(i);try{(await e.ssrLoadModule("@drincs/pixi-vn/characters")).RegisteredCharacters?.clear?.();}catch{}try{(await e.ssrLoadModule("@drincs/pixi-vn/narration")).RegisteredLabels?.clear?.();}catch{}let r=await V(s=>e.ssrLoadModule(s),t.root);await O(s=>e.ssrLoadModule(s),r),await I(s=>e.ssrLoadModule(s)),b$1();for(let s of B)s();}let p={characters:null,labels:null,manifest:y??null,canvasOptions:null};function w(e,r){return (s,i)=>{if(i.setHeader("Content-Type","application/json"),s.method==="GET"){let u=p[e];if(u===null){i.statusCode=404,i.end(JSON.stringify({error:`${r} not initialized`}));return}i.statusCode=200,i.end(JSON.stringify(u));return}if(s.method==="POST"){let u="";s.on("data",a=>{u+=a.toString();}),s.on("end",()=>{try{p[e]=JSON.parse(u),i.statusCode=201,i.end(JSON.stringify({message:`${r} updated successfully`}));}catch{i.statusCode=400,i.end(JSON.stringify({error:`Invalid JSON format for ${r}`}));}});}}}return {name:"vite-plugin-pixi-vn",enforce:"pre",api:{contentLoaded:f,get characters(){return c},onReload(e){B.push(e);},setExternalLabels(e,r){E.set(e,r),b$1();},clearExternalLabels(e){E.delete(e),b$1();},setAssetsManifest(e){y=e,p.manifest=e,b$1();}},config(e,r){if(r.command==="serve"&&l.length>0)return {ssr:{noExternal:["@drincs/pixi-vn"]}}},configResolved(e){t=e,l.length===0&&!S&&(b$1(),d$1());},async buildStart(){if(t?.command!=="build"||l.length===0&&!S)return;let{createServer:e}=await import('vite'),r=await e({root:t.root,configFile:false,resolve:t.resolve,server:{middlewareMode:true},appType:"custom",logLevel:"silent",optimizeDeps:{noDiscovery:true},ssr:{noExternal:["@drincs/pixi-vn"]}});try{await J(s=>r.ssrLoadModule(s),t.root);}catch{d$1();}finally{await r.close();}},configureServer(e){(l.length>0||S)&&J(r=>e.ssrLoadModule(r),t.root).catch(()=>{d$1();}),e.middlewares.use(a$1,w("characters","Characters")),e.middlewares.use(b,w("labels","Labels")),e.middlewares.use(c$1,w("manifest","Manifest")),e.middlewares.use(d,w("canvasOptions","Canvas options"));},async hotUpdate({file:e,server:r}){let s=L();if(s&&e===s)return [];if(l.length>0&&h.has(e)){try{await H(r);}catch(i){t?.logger.error(`${v} Failed to reload content.`,{error:i instanceof Error?i:new Error(String(i)),timestamp:true});}return []}if(S)try{await I(i=>r.ssrLoadModule(i)),b$1();}catch(i){t?.logger.error(`${v} Failed to refresh the assets manifest.`,{error:i instanceof Error?i:new Error(String(i)),timestamp:true});}}}}export{at as vitePluginPixivn};
1
+ import {a as a$1,b,c as c$1,d}from'./chunk-3BBZHKU4.mjs';export{c as PIXIVN_DEV_API_ASSETS_MANIFEST,d as PIXIVN_DEV_API_CANVAS_OPTIONS,a as PIXIVN_DEV_API_CHARACTERS,b as PIXIVN_DEV_API_LABELS}from'./chunk-3BBZHKU4.mjs';import {a,c}from'./chunk-K7JIC2F2.mjs';import {mkdirSync,writeFileSync,readFileSync}from'fs';import {isAbsolute,resolve,dirname}from'path';import {glob}from'tinyglobby';var G=a((me,R)=>{var A=process||{},D=A.argv||[],I=A.env||{},Z=!(I.NO_COLOR||D.includes("--no-color"))&&(!!I.FORCE_COLOR||D.includes("--color")||A.platform==="win32"||(A.stdout||{}).isTTY&&I.TERM!=="dumb"||!!I.CI),q=(r,e,u=r)=>m=>{let l=""+m,c=l.indexOf(e,r.length);return ~c?r+ee(l,e,u,c)+e:r+l+e},ee=(r,e,u,m)=>{let l="",c=0;do l+=r.substring(c,m)+u,c=m+e.length,m=r.indexOf(e,c);while(~m);return l+r.substring(c)},j=(r=Z)=>{let e=r?q:()=>String;return {isColorSupported:r,reset:e("\x1B[0m","\x1B[0m"),bold:e("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:e("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:e("\x1B[3m","\x1B[23m"),underline:e("\x1B[4m","\x1B[24m"),inverse:e("\x1B[7m","\x1B[27m"),hidden:e("\x1B[8m","\x1B[28m"),strikethrough:e("\x1B[9m","\x1B[29m"),black:e("\x1B[30m","\x1B[39m"),red:e("\x1B[31m","\x1B[39m"),green:e("\x1B[32m","\x1B[39m"),yellow:e("\x1B[33m","\x1B[39m"),blue:e("\x1B[34m","\x1B[39m"),magenta:e("\x1B[35m","\x1B[39m"),cyan:e("\x1B[36m","\x1B[39m"),white:e("\x1B[37m","\x1B[39m"),gray:e("\x1B[90m","\x1B[39m"),bgBlack:e("\x1B[40m","\x1B[49m"),bgRed:e("\x1B[41m","\x1B[49m"),bgGreen:e("\x1B[42m","\x1B[49m"),bgYellow:e("\x1B[43m","\x1B[49m"),bgBlue:e("\x1B[44m","\x1B[49m"),bgMagenta:e("\x1B[45m","\x1B[49m"),bgCyan:e("\x1B[46m","\x1B[49m"),bgWhite:e("\x1B[47m","\x1B[49m"),blackBright:e("\x1B[90m","\x1B[39m"),redBright:e("\x1B[91m","\x1B[39m"),greenBright:e("\x1B[92m","\x1B[39m"),yellowBright:e("\x1B[93m","\x1B[39m"),blueBright:e("\x1B[94m","\x1B[39m"),magentaBright:e("\x1B[95m","\x1B[39m"),cyanBright:e("\x1B[96m","\x1B[39m"),whiteBright:e("\x1B[97m","\x1B[39m"),bgBlackBright:e("\x1B[100m","\x1B[49m"),bgRedBright:e("\x1B[101m","\x1B[49m"),bgGreenBright:e("\x1B[102m","\x1B[49m"),bgYellowBright:e("\x1B[103m","\x1B[49m"),bgBlueBright:e("\x1B[104m","\x1B[49m"),bgMagentaBright:e("\x1B[105m","\x1B[49m"),bgCyanBright:e("\x1B[106m","\x1B[49m"),bgWhiteBright:e("\x1B[107m","\x1B[49m")}};R.exports=j();R.exports.createColors=j;});var F=c(G(),1);var v=F.default.cyan("(pixi-vn)"),V="virtual:pixi-vn-testing",K=`\0${V}`;function x(r){return r?Array.isArray(r)?r:[r]:[]}function oe(r){return r?r.bundles.map(e=>e.name):[]}function ce(r){if(!r)return [];let e=new Set;for(let u of r.bundles){let m=u.assets;if(Array.isArray(m))for(let l of m){let c=l.alias;if(c)for(let g of Array.isArray(c)?c:[c])e.add(g);}else if(m&&typeof m=="object")for(let l of Object.keys(m))e.add(l);}return Array.from(e)}function le(r){let e=[],u=[];for(let m of r)try{let l=readFileSync(m,"utf-8"),c=/newLabel\(\s*["']([^"']+)["']/g,g;for(;(g=c.exec(l))!==null;)u.push(g[1]);let h=/new\s+\w*[Cc]haracter\(\s*["']([^"']+)["']/g;for(;(g=h.exec(l))!==null;)e.push(g[1]);}catch{}return {charIds:e,labelIds:u}}function de(r){let e,u,m=new Promise(t=>{u=t;}),l=[...x(r?.content),...x(r?.characters),...x(r?.labels)],c=[],g=[],h=new Set,L=[],w=typeof r?.assetsManifest=="function",H=r?.testing===false,$=typeof r?.testing=="object"?r.testing.windowKey:void 0,y=typeof r?.assetsManifest=="function"?void 0:r?.assetsManifest;async function P(t){if(typeof r?.assetsManifest=="function")try{let n=await r.assetsManifest(t);y=n,p.manifest=n??null;}catch(n){e?.logger.error(`${v} Failed to resolve the assets manifest.`,{error:n instanceof Error?n:new Error(String(n)),timestamp:true});}}let E=new Map;function B(){if(!r?.typeFilePath||!e)return null;let t=r.typeFilePath;return isAbsolute(t)?t:resolve(e.root,t)}function T(){let t=[...g,...Array.from(E.values()).flat()];return Array.from(new Set(t))}function U(t,n,s,i,f){mkdirSync(dirname(t),{recursive:true});let a=["/* eslint-disable */","// noinspection JSUnusedGlobalSymbols","// This file is auto-generated by @drincs/pixi-vn vite plugin. Do not edit manually."];if(n.length>0){a.push('declare module "@drincs/pixi-vn/characters" {'),a.push(" interface PixivnCharacterIds {");for(let o of n)a.push(` ${JSON.stringify(o)}: never;`);a.push(" }"),a.push("}");}if(s.length>0){a.push('declare module "@drincs/pixi-vn/narration" {'),a.push(" interface PixivnLabelIds {");for(let o of s)a.push(` ${JSON.stringify(o)}: never;`);a.push(" }"),a.push("}");}if(i.length>0||f.length>0){if(a.push('declare module "@drincs/pixi-vn/canvas" {'),i.length>0){a.push(" interface PixivnBundleIds {");for(let o of i)a.push(` ${JSON.stringify(o)}: never;`);a.push(" }");}if(f.length>0){a.push(" interface PixivnAssetAliasIds {");for(let o of f)a.push(` ${JSON.stringify(o)}: never;`);a.push(" }");}a.push("}");}a.push(`export const characterIds = ${JSON.stringify(n)} as const;`);{let o=Object.fromEntries(n.map(d=>[d,d]));a.push(`export const characterIdsEnum = ${JSON.stringify(o)} as const;`);}a.push(`export const labelIds = ${JSON.stringify(s)} as const;`);{let o=Object.fromEntries(s.map(d=>[d,d]));a.push(`export const labelIdsEnum = ${JSON.stringify(o)} as const;`);}a.push(`export const bundleIds = ${JSON.stringify(i)} as const;`);{let o=Object.fromEntries(i.map(d=>[d,d]));a.push(`export const bundleIdsEnum = ${JSON.stringify(o)} as const;`);}a.push(`export const assetAliasIds = ${JSON.stringify(f)} as const;`);{let o=Object.fromEntries(f.map(d=>[d,d]));a.push(`export const assetAliasIdsEnum = ${JSON.stringify(o)} as const;`);}a.push(""),writeFileSync(t,a.join(`
2
+ `),"utf-8");}function z(){p.characters=c,p.labels=T();}function b$1(){z();let t=B();if(t)try{U(t,c.map(n=>n.id),T(),oe(y),ce(y));}catch(n){e?.logger.error(`${v} Failed to write keys file "${t}".`,{error:n instanceof Error?n:new Error(String(n)),timestamp:true});}}async function O(t,n=[]){try{c=(await t("@drincs/pixi-vn/characters")).RegisteredCharacters?.values()??[];}catch{c=[];}try{g=(await t("@drincs/pixi-vn/narration")).RegisteredLabels?.keys()??[];}catch{g=[];}if(n.length>0){let{charIds:i,labelIds:f}=le(n),a=new Set(c.map(d=>d.id)),o=new Set(g);for(let d of i)a.has(d)||c.push({id:d});for(let d of f)o.has(d)||g.push(d);}let s=c.map(i=>i.id).join(", ")||"none";e?.logger.info(`${v} ${F.default.dim(`${c.length} character(s): [${s}], ${g.length} label(s)`)}`,{timestamp:true});}async function J(t,n){let s=[],i=[...x(r?.characters),...x(r?.labels)],f=await glob(i,{cwd:n,absolute:true,onlyFiles:true});for(let o of f){h.add(o);try{await t(o);}catch{s.push(o);}}await O(t,s),b$1();let a=await glob(x(r?.content),{cwd:n,absolute:true,onlyFiles:true});for(let o of a){h.add(o);try{await t(o);}catch{s.push(o);}}return s}async function k(t,n){try{await t("@drincs/pixi-vn/characters");}catch{}try{await t("@drincs/pixi-vn/narration");}catch{}let s=await J(t,n);await O(t,s),await P(t),b$1(),u();}async function W(t){for(let s of h)for(let i of t.moduleGraph.getModulesByFile(s)??[])t.moduleGraph.invalidateModule(i);try{(await t.ssrLoadModule("@drincs/pixi-vn/characters")).RegisteredCharacters?.clear?.();}catch{}try{(await t.ssrLoadModule("@drincs/pixi-vn/narration")).RegisteredLabels?.clear?.();}catch{}let n=await J(s=>t.ssrLoadModule(s),e.root);await O(s=>t.ssrLoadModule(s),n),await P(s=>t.ssrLoadModule(s)),b$1();for(let s of L)s();}let p={characters:null,labels:null,manifest:y??null,canvasOptions:null};function S(t,n){return (s,i)=>{if(i.setHeader("Content-Type","application/json"),s.method==="GET"){let f=p[t];if(f===null){i.statusCode=404,i.end(JSON.stringify({error:`${n} not initialized`}));return}i.statusCode=200,i.end(JSON.stringify(f));return}if(s.method==="POST"){let f="";s.on("data",a=>{f+=a.toString();}),s.on("end",()=>{try{p[t]=JSON.parse(f),i.statusCode=201,i.end(JSON.stringify({message:`${n} updated successfully`}));}catch{i.statusCode=400,i.end(JSON.stringify({error:`Invalid JSON format for ${n}`}));}});}}}return {name:"vite-plugin-pixi-vn",enforce:"pre",api:{contentLoaded:m,get characters(){return c},onReload(t){L.push(t);},setExternalLabels(t,n){E.set(t,n),b$1();},clearExternalLabels(t){E.delete(t),b$1();},setAssetsManifest(t){y=t,p.manifest=t,b$1();}},resolveId(t){if(t===V)return K},load(t){if(t===K)return `import { Game } from "@drincs/pixi-vn";
3
+ Game.testing.enable(${$?JSON.stringify({windowKey:$}):""});
4
+ `},transformIndexHtml(){if(!(H||e?.command!=="serve"))return [{tag:"script",attrs:{type:"module",src:`/@id/${V}`},injectTo:"head-prepend"}]},config(t,n){if(n.command==="serve"&&l.length>0)return {ssr:{noExternal:["@drincs/pixi-vn"]}}},configResolved(t){e=t,l.length===0&&!w&&(b$1(),u());},async buildStart(){if(e?.command!=="build"||l.length===0&&!w)return;let{createServer:t}=await import('vite'),n=await t({root:e.root,configFile:false,resolve:e.resolve,server:{middlewareMode:true},appType:"custom",logLevel:"silent",optimizeDeps:{noDiscovery:true},ssr:{noExternal:["@drincs/pixi-vn"]}});try{await k(s=>n.ssrLoadModule(s),e.root);}catch{u();}finally{await n.close();}},configureServer(t){(l.length>0||w)&&k(n=>t.ssrLoadModule(n),e.root).catch(()=>{u();}),t.middlewares.use(a$1,S("characters","Characters")),t.middlewares.use(b,S("labels","Labels")),t.middlewares.use(c$1,S("manifest","Manifest")),t.middlewares.use(d,S("canvasOptions","Canvas options"));},async hotUpdate({file:t,server:n}){let s=B();if(s&&t===s)return [];if(l.length>0&&h.has(t)){try{await W(n);}catch(i){e?.logger.error(`${v} Failed to reload content.`,{error:i instanceof Error?i:new Error(String(i)),timestamp:true});}return []}if(w)try{await P(i=>n.ssrLoadModule(i)),b$1();}catch(i){e?.logger.error(`${v} Failed to refresh the assets manifest.`,{error:i instanceof Error?i:new Error(String(i)),timestamp:true});}}}}export{de as vitePluginPixivn};
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@drincs/pixi-vn",
3
- "version": "1.9.0",
3
+ "version": "1.9.2",
4
4
  "type": "module",
5
- "description": "Pixi'VN is a npm package that provides various features for creating visual novels.",
5
+ "description": "Pixi'VN is a very versatile and powerful game/story-driven engine.",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.mjs",
8
8
  "types": "./dist/index.d.ts",