@drincs/pixi-vn-json 1.12.0 → 1.12.1

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/core.d.cts CHANGED
@@ -413,7 +413,7 @@ type PixiVNJsonSoundEdit = {
413
413
  type: "sound";
414
414
  operationType: "edit";
415
415
  alias: string;
416
- props: Partial<Pick<MediaInterface, "speed" | "volume" | "muted" | "loop" | "paused">>;
416
+ props: Partial<Pick<MediaInterface, "speed" | "muted" | "loop" | "paused"> & Pick<SoundPlayOptionsWithChannel, "volume">>;
417
417
  };
418
418
  type PixiVNJsonSound = PixiVNJsonSoundPlay | PixiVNJsonSoundRemove | PixiVNJsonSoundPauseResume | PixiVNJsonSoundEdit;
419
419
 
@@ -421,7 +421,12 @@ type PixiVNJsonOperationString = {
421
421
  type: "operationtoconvert";
422
422
  values: (string | PixiVNJsonValueGet | PixiVNJsonConditionalStatements<string | PixiVNJsonValueGet>)[];
423
423
  };
424
- type PixiVNJsonOperation = PixiVNJsonValueSet | PixiVNJsonCanvas | PixiVNJsonSound | PixiVNJsonNarration;
424
+ type PixiVNJsonOperation = (PixiVNJsonValueSet | PixiVNJsonCanvas | PixiVNJsonSound | PixiVNJsonNarration) & {
425
+ /**
426
+ * This value is used by the system to know where this operation is from, for example, if is generated from a string operation.
427
+ */
428
+ $origin?: string;
429
+ };
425
430
  type PixiVNJsonConditionalOperation = PixiVNJsonOperation | PixiVNJsonIfElse<PixiVNJsonOperation> | PixiVNJsonOperationString;
426
431
 
427
432
  type PixiVNJsonChoice = {
@@ -466,7 +471,7 @@ type PixiVNJsonDialog<Text = string> = {
466
471
  */
467
472
  text: Text;
468
473
  } | Text;
469
- type PixiVNJsonLabelToOpen<T extends {} = {}> = {
474
+ type PixiVNJsonLabelToOpen<T extends {} = object> = {
470
475
  /**
471
476
  * The id of the label to open.
472
477
  */
@@ -483,7 +488,7 @@ type PixiVNJsonLabelToOpen<T extends {} = {}> = {
483
488
  * **It is not recommended to use it, use it only if necessary**. The parameters to be passed to the label. If you want to pass an object, use the {@link PixiVNJsonLabelToOpen.props} attribute.
484
489
  * "params" attribute will be stored in the temp storage with the key: {@link PIXIVNJSON_PARAM_ID} + ({@link narration.openedLabels.length} - 1).
485
490
  */
486
- params?: any[];
491
+ params?: unknown[];
487
492
  };
488
493
  /**
489
494
  * Steps of a label.
package/dist/core.d.ts CHANGED
@@ -413,7 +413,7 @@ type PixiVNJsonSoundEdit = {
413
413
  type: "sound";
414
414
  operationType: "edit";
415
415
  alias: string;
416
- props: Partial<Pick<MediaInterface, "speed" | "volume" | "muted" | "loop" | "paused">>;
416
+ props: Partial<Pick<MediaInterface, "speed" | "muted" | "loop" | "paused"> & Pick<SoundPlayOptionsWithChannel, "volume">>;
417
417
  };
418
418
  type PixiVNJsonSound = PixiVNJsonSoundPlay | PixiVNJsonSoundRemove | PixiVNJsonSoundPauseResume | PixiVNJsonSoundEdit;
419
419
 
@@ -421,7 +421,12 @@ type PixiVNJsonOperationString = {
421
421
  type: "operationtoconvert";
422
422
  values: (string | PixiVNJsonValueGet | PixiVNJsonConditionalStatements<string | PixiVNJsonValueGet>)[];
423
423
  };
424
- type PixiVNJsonOperation = PixiVNJsonValueSet | PixiVNJsonCanvas | PixiVNJsonSound | PixiVNJsonNarration;
424
+ type PixiVNJsonOperation = (PixiVNJsonValueSet | PixiVNJsonCanvas | PixiVNJsonSound | PixiVNJsonNarration) & {
425
+ /**
426
+ * This value is used by the system to know where this operation is from, for example, if is generated from a string operation.
427
+ */
428
+ $origin?: string;
429
+ };
425
430
  type PixiVNJsonConditionalOperation = PixiVNJsonOperation | PixiVNJsonIfElse<PixiVNJsonOperation> | PixiVNJsonOperationString;
426
431
 
427
432
  type PixiVNJsonChoice = {
@@ -466,7 +471,7 @@ type PixiVNJsonDialog<Text = string> = {
466
471
  */
467
472
  text: Text;
468
473
  } | Text;
469
- type PixiVNJsonLabelToOpen<T extends {} = {}> = {
474
+ type PixiVNJsonLabelToOpen<T extends {} = object> = {
470
475
  /**
471
476
  * The id of the label to open.
472
477
  */
@@ -483,7 +488,7 @@ type PixiVNJsonLabelToOpen<T extends {} = {}> = {
483
488
  * **It is not recommended to use it, use it only if necessary**. The parameters to be passed to the label. If you want to pass an object, use the {@link PixiVNJsonLabelToOpen.props} attribute.
484
489
  * "params" attribute will be stored in the temp storage with the key: {@link PIXIVNJSON_PARAM_ID} + ({@link narration.openedLabels.length} - 1).
485
490
  */
486
- params?: any[];
491
+ params?: unknown[];
487
492
  };
488
493
  /**
489
494
  * Steps of a label.
package/dist/importer.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var narration=require('@drincs/pixi-vn/narration'),core=require('@drincs/pixi-vn-json/core'),pixiVn=require('@drincs/pixi-vn'),translator=require('@drincs/pixi-vn-json/translator'),storage=require('@drincs/pixi-vn/storage');var K=Object.create;var E=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty;var te=(a,i,t)=>i in a?E(a,i,{enumerable:true,configurable:true,writable:true,value:t}):a[i]=t;var H=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(i,t)=>(typeof require<"u"?require:i)[t]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var R=(a,i)=>()=>(i||a((i={exports:{}}).exports,i),i.exports);var ie=(a,i,t,o)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of Y(i))!ee.call(a,n)&&n!==t&&E(a,n,{get:()=>i[n],enumerable:!(o=Q(i,n))||o.enumerable});return a};var ne=(a,i,t)=>(t=a!=null?K(Z(a)):{},ie(E(t,"default",{value:a,enumerable:true}),a));var T=(a,i,t)=>te(a,typeof i!="symbol"?i+"":i,t);var q=R((A,U)=>{(function(a,i){typeof A=="object"?U.exports=A=i():typeof define=="function"&&define.amd?define([],i):a.CryptoJS=i();})(A,function(){var a=a||(function(i,t){var o;if(typeof window<"u"&&window.crypto&&(o=window.crypto),typeof self<"u"&&self.crypto&&(o=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(o=globalThis.crypto),!o&&typeof window<"u"&&window.msCrypto&&(o=window.msCrypto),!o&&typeof global<"u"&&global.crypto&&(o=global.crypto),!o&&typeof H=="function")try{o=H("crypto");}catch{}var n=function(){if(o){if(typeof o.getRandomValues=="function")try{return o.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof o.randomBytes=="function")try{return o.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},s=Object.create||(function(){function e(){}return function(r){var f;return e.prototype=r,f=new e,e.prototype=null,f}})(),l={},u=l.lib={},g=u.Base=(function(){return {extend:function(e){var r=s(this);return e&&r.mixIn(e),(!r.hasOwnProperty("init")||this.init===r.init)&&(r.init=function(){r.$super.init.apply(this,arguments);}),r.init.prototype=r,r.$super=this,r},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var r in e)e.hasOwnProperty(r)&&(this[r]=e[r]);e.hasOwnProperty("toString")&&(this.toString=e.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),x=u.WordArray=g.extend({init:function(e,r){e=this.words=e||[],r!=t?this.sigBytes=r:this.sigBytes=e.length*4;},toString:function(e){return (e||V).stringify(this)},concat:function(e){var r=this.words,f=e.words,c=this.sigBytes,v=e.sigBytes;if(this.clamp(),c%4)for(var P=0;P<v;P++){var k=f[P>>>2]>>>24-P%4*8&255;r[c+P>>>2]|=k<<24-(c+P)%4*8;}else for(var L=0;L<v;L+=4)r[c+L>>>2]=f[L>>>2];return this.sigBytes+=v,this},clamp:function(){var e=this.words,r=this.sigBytes;e[r>>>2]&=4294967295<<32-r%4*8,e.length=i.ceil(r/4);},clone:function(){var e=g.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var r=[],f=0;f<e;f+=4)r.push(n());return new x.init(r,e)}}),p=l.enc={},V=p.Hex={stringify:function(e){for(var r=e.words,f=e.sigBytes,c=[],v=0;v<f;v++){var P=r[v>>>2]>>>24-v%4*8&255;c.push((P>>>4).toString(16)),c.push((P&15).toString(16));}return c.join("")},parse:function(e){for(var r=e.length,f=[],c=0;c<r;c+=2)f[c>>>3]|=parseInt(e.substr(c,2),16)<<24-c%8*4;return new x.init(f,r/2)}},b=p.Latin1={stringify:function(e){for(var r=e.words,f=e.sigBytes,c=[],v=0;v<f;v++){var P=r[v>>>2]>>>24-v%4*8&255;c.push(String.fromCharCode(P));}return c.join("")},parse:function(e){for(var r=e.length,f=[],c=0;c<r;c++)f[c>>>2]|=(e.charCodeAt(c)&255)<<24-c%4*8;return new x.init(f,r)}},N=p.Utf8={stringify:function(e){try{return decodeURIComponent(escape(b.stringify(e)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(e){return b.parse(unescape(encodeURIComponent(e)))}},h=u.BufferedBlockAlgorithm=g.extend({reset:function(){this._data=new x.init,this._nDataBytes=0;},_append:function(e){typeof e=="string"&&(e=N.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes;},_process:function(e){var r,f=this._data,c=f.words,v=f.sigBytes,P=this.blockSize,k=P*4,L=v/k;e?L=i.ceil(L):L=i.max((L|0)-this._minBufferSize,0);var C=L*P,j=i.min(C*4,v);if(C){for(var D=0;D<C;D+=P)this._doProcessBlock(c,D);r=c.splice(0,C),f.sigBytes-=j;}return new x.init(r,j)},clone:function(){var e=g.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});u.Hasher=h.extend({cfg:g.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset();},reset:function(){h.reset.call(this),this._doReset();},update:function(e){return this._append(e),this._process(),this},finalize:function(e){e&&this._append(e);var r=this._doFinalize();return r},blockSize:512/32,_createHelper:function(e){return function(r,f){return new e.init(f).finalize(r)}},_createHmacHelper:function(e){return function(r,f){return new y.HMAC.init(e,f).finalize(r)}}});var y=l.algo={};return l})(Math);return a});});var M=R((B,F)=>{(function(a,i){typeof B=="object"?F.exports=B=i(q()):typeof define=="function"&&define.amd?define(["./core"],i):i(a.CryptoJS);})(B,function(a){return (function(){var i=a,t=i.lib,o=t.WordArray,n=t.Hasher,s=i.algo,l=[],u=s.SHA1=n.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(g,x){for(var p=this._hash.words,V=p[0],b=p[1],N=p[2],h=p[3],d=p[4],y=0;y<80;y++){if(y<16)l[y]=g[x+y]|0;else {var e=l[y-3]^l[y-8]^l[y-14]^l[y-16];l[y]=e<<1|e>>>31;}var r=(V<<5|V>>>27)+d+l[y];y<20?r+=(b&N|~b&h)+1518500249:y<40?r+=(b^N^h)+1859775393:y<60?r+=(b&N|b&h|N&h)-1894007588:r+=(b^N^h)-899497514,d=h,h=N,N=b<<30|b>>>2,b=V,V=r;}p[0]=p[0]+V|0,p[1]=p[1]+b|0,p[2]=p[2]+N|0,p[3]=p[3]+h|0,p[4]=p[4]+d|0;},_doFinalize:function(){var g=this._data,x=g.words,p=this._nDataBytes*8,V=g.sigBytes*8;return x[V>>>5]|=128<<24-V%32,x[(V+64>>>9<<4)+14]=Math.floor(p/4294967296),x[(V+64>>>9<<4)+15]=p,g.sigBytes=x.length*4,this._process(),this._hash},clone:function(){var g=n.clone.call(this);return g._hash=this._hash.clone(),g}});i.SHA1=n._createHelper(u),i.HmacSHA1=n._createHmacHelper(u);})(),a.SHA1});});var w;(n=>(n.log=(s,...l)=>console.log(`[Pixi\u2019VN Json] ${s}`,...l),n.warn=(s,...l)=>console.warn(`[Pixi\u2019VN Json] ${s}`,...l),n.error=(s,...l)=>console.error(`[Pixi\u2019VN Json] ${s}`,...l),n.info=(s,...l)=>console.info(`[Pixi\u2019VN Json] ${s}`,...l)))(w||(w={}));function z(a){let i="";return a.values.forEach(t=>{if(typeof t=="string")i+=t;else {let o=core.JsonUnifier.getLogichValue(t);i+=`${o}`;}}),i}async function I(a,i){let t=core.JsonUnifier.getLogichValue(a);if(t)switch(t.type){case "sound":core.JsonUnifier.soundOperation(t);break;case "assets":case "bundle":await core.JsonUnifier.loadAssets(t);break;case "image":await core.JsonUnifier.imageOperation(t);break;case "video":await core.JsonUnifier.videoOperation(t);break;case "imagecontainer":await core.JsonUnifier.imageContainerOperation(t);break;case "text":await core.JsonUnifier.textOperation(t);break;case "canvaselement":await core.JsonUnifier.canvasElementOperation(t);break;case "value":core.JsonUnifier.setStorageValue(t);break;case "operationtoconvert":if(i){let o=z(t),n=await i(o);n&&await I(n,i);}break;case "input":case "dialogue":core.JsonUnifier.narrationOperation(t);break;case "shake":await core.JsonUnifier.effectOperation(t);break;case "animate":case "animate-sequence":core.JsonUnifier.animateOperation(t);break}}function W(a){let i=core.JsonUnifier.getLogichValue(a);i&&i.type==="value"&&i.storageOperationType==="set"&&(i.storageType==="storage"||i.storageType==="tempstorage")&&core.JsonUnifier.setInitialStorageValue(i);}async function ae(a,i={}){if(!Array.isArray(a))if(typeof a=="object"||typeof a=="string")a=[a];else {w.error("Error parsing imported Pixi'VN JSON: data is not an object");return}let t=a.map(async s=>{if(typeof s=="string")try{s=JSON.parse(s);}catch(l){w.error("Error parsing imported Pixi'VN JSON",l),s={};}return s}),n=(await Promise.all(t)).map(async s=>{let l=[];if(s.initialOperations)for(let u of s.initialOperations)W(u);if(s.labels){let u=s.labels;for(let g in u)try{let x=u[g],p=new _(g,x,void 0,i);narration.RegisteredLabels.add(p);}catch(x){w.error(`Error creating JSON label ${g}`,x);}}return Promise.all(l)});await Promise.all(n);}var X=ne(M());var $="___param___";var _=class extends narration.LabelAbstract{constructor(t,o,n,s={}){n||(n={}),n.onLoadingLabel=async()=>{for(let l of o){let u;if(typeof l=="function"?u=l():u=l,u=core.JsonUnifier.getConditionalStep(u),u.operations)try{let g=u.operations.map(x=>core.JsonUnifier.loadAssets(x));await Promise.all(g);}catch(g){w.error("The operation in the onLoadingLabel function of the label has an error:",g);}}};super(t,n);T(this,"_steps");T(this,"operationStringConvert");T(this,"skipEmptyDialogs",false);this._steps=o,this.operationStringConvert=s.operationStringConvert,this.skipEmptyDialogs=s.skipEmptyDialogs||false;}get steps(){return this._steps.map(t=>this.stepConverter(t))}get stepCount(){return this._steps.length}getStepById(t){if(t<0||t>=this._steps.length)return;let o=this._steps[t];return this.stepConverter(o)}getStepSha(t){if(t<0||t>=this.steps.length)return;let o=this._steps[t];return (0, X.default)(o.toString().toLocaleLowerCase()).toString()}getDialogueText(t){let o="";if(Array.isArray(t)){let n=[];t.forEach(s=>{if(typeof s=="string")n.push(s);else if(s&&typeof s=="object"){let l=core.JsonUnifier.getLogichValue(s);l?(l&&!Array.isArray(l)&&typeof l=="object"&&(l=core.JsonUnifier.getLogichValue(l)||""),Array.isArray(l)?n=n.map(u=>`${u}`).concat(l):n.push(`${l}`)):n.push(`${s}`);}else n.push(`${s}`);}),o=n;}else {let n=core.JsonUnifier.getLogichValue(t);n&&!Array.isArray(n)&&typeof n=="object"&&(n=core.JsonUnifier.getLogichValue(n)),n&&Array.isArray(n)?o=n.map(s=>`${s}`):o=`${n}`;}return o}getDialogue(t){if(t==null)return;let o=core.JsonUnifier.getLogichValue(t);return o==null?`${o}`:typeof o=="object"&&"character"in o&&"text"in o?{character:o.character,text:translator.translator.t(this.getDialogueText(o.text))}:translator.translator.t(this.getDialogueText(o))}getChoices(t){return core.JsonUnifier.getLogichValue(t)?.map(s=>core.JsonUnifier.getLogichValue(s)).filter(s=>s!==void 0)}stepConverter(t){return async o=>{let n=typeof t=="function"?t():t;n=pixiVn.createExportableElement(n),n=core.JsonUnifier.getConditionalStep(n);let s=this.operationStringConvert?h=>this.operationStringConvert(h,n,o):void 0,{operations:l=[]}=n;for(let h of l)await I(h,s);let{labelToOpen:u=[]}=n,g=this.getChoices(n.choices),x=core.JsonUnifier.getLogichValue(n.glueEnabled),p=this.getDialogue(n.dialogue),V=[];Array.isArray(u)||(u=[u]),u.forEach(h=>{let d=core.JsonUnifier.getLogichValue(h);d&&V.push(d);});let b=core.JsonUnifier.getLogichValue(n.goNextStep),N=core.JsonUnifier.getLogichValue(n.end);if(g){let h=g.map(d=>{let y="";if(Array.isArray(d.text)){let r=[];d.text.forEach(f=>{if(typeof f=="string")r.push(translator.translator.t(f));else if(f&&typeof f=="object"){let c=core.JsonUnifier.getLogichValue(f);c&&!Array.isArray(c)&&typeof c=="object"&&(c=core.JsonUnifier.getLogichValue(c)||""),c&&(Array.isArray(c)?r=r.concat(translator.translator.t(c)):r.push(translator.translator.t(c)));}}),y=r;}else typeof d.text=="string"&&(y=translator.translator.t(d.text));return {label:d.label,text:y,props:d.props,type:d.type,oneTime:d.oneTime,onlyHaveNoChoice:d.onlyHaveNoChoice,autoSelect:d.autoSelect}});narration.narration.choices=h;}else narration.narration.choices=void 0;p!==void 0&&(narration.narration.dialogue=p,this.skipEmptyDialogs&&typeof p=="string"&&(p===""||RegExp(/^\s+$/).test(p))&&(b=true)),x?narration.narration.dialogGlue=true:x===false&&(narration.narration.dialogGlue=false);for(let h of V){let d=h.label;typeof d=="object"&&(d=core.JsonUnifier.getLogichValue(d)||"");let y=h.params?.map(e=>core.JsonUnifier.getLogichValue(e));o={...o,...h.props},h.type==="jump"?(narration.narration.openedLabels.length>0&&narration.narration.closeCurrentLabel(),storage.storage.setTempVariable(`${$}${narration.narration.openedLabels.length}`,y),await narration.narration.call(d,o)):(storage.storage.setTempVariable(`${$}${narration.narration.openedLabels.length}`,y),await narration.narration.call(d,o));}N==="game_end"?(narration.narration.closeAllLabels(),await narration.narration.continue(o,{runNow:true})):N==="label_end"&&narration.narration.closeCurrentLabel(),b&&await narration.narration.continue(o,{runNow:true});}}};exports.LabelJson=_;exports.importPixiVNJson=ae;
1
+ 'use strict';var core=require('@drincs/pixi-vn-json/core'),narration=require('@drincs/pixi-vn/narration'),pixiVn=require('@drincs/pixi-vn'),translator=require('@drincs/pixi-vn-json/translator'),storage=require('@drincs/pixi-vn/storage');var K=Object.create;var D=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty;var te=(a,i,t)=>i in a?D(a,i,{enumerable:true,configurable:true,writable:true,value:t}):a[i]=t;var H=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(i,t)=>(typeof require<"u"?require:i)[t]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var R=(a,i)=>()=>(i||a((i={exports:{}}).exports,i),i.exports);var ie=(a,i,t,o)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of Y(i))!ee.call(a,n)&&n!==t&&D(a,n,{get:()=>i[n],enumerable:!(o=Q(i,n))||o.enumerable});return a};var ne=(a,i,t)=>(t=a!=null?K(Z(a)):{},ie(D(t,"default",{value:a,enumerable:true}),a));var T=(a,i,t)=>te(a,typeof i!="symbol"?i+"":i,t);var q=R((A,U)=>{(function(a,i){typeof A=="object"?U.exports=A=i():typeof define=="function"&&define.amd?define([],i):a.CryptoJS=i();})(A,function(){var a=a||(function(i,t){var o;if(typeof window<"u"&&window.crypto&&(o=window.crypto),typeof self<"u"&&self.crypto&&(o=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(o=globalThis.crypto),!o&&typeof window<"u"&&window.msCrypto&&(o=window.msCrypto),!o&&typeof global<"u"&&global.crypto&&(o=global.crypto),!o&&typeof H=="function")try{o=H("crypto");}catch{}var n=function(){if(o){if(typeof o.getRandomValues=="function")try{return o.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof o.randomBytes=="function")try{return o.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},s=Object.create||(function(){function e(){}return function(r){var p;return e.prototype=r,p=new e,e.prototype=null,p}})(),l={},u=l.lib={},g=u.Base=(function(){return {extend:function(e){var r=s(this);return e&&r.mixIn(e),(!r.hasOwnProperty("init")||this.init===r.init)&&(r.init=function(){r.$super.init.apply(this,arguments);}),r.init.prototype=r,r.$super=this,r},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var r in e)e.hasOwnProperty(r)&&(this[r]=e[r]);e.hasOwnProperty("toString")&&(this.toString=e.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),x=u.WordArray=g.extend({init:function(e,r){e=this.words=e||[],r!=t?this.sigBytes=r:this.sigBytes=e.length*4;},toString:function(e){return (e||V).stringify(this)},concat:function(e){var r=this.words,p=e.words,c=this.sigBytes,v=e.sigBytes;if(this.clamp(),c%4)for(var P=0;P<v;P++){var k=p[P>>>2]>>>24-P%4*8&255;r[c+P>>>2]|=k<<24-(c+P)%4*8;}else for(var L=0;L<v;L+=4)r[c+L>>>2]=p[L>>>2];return this.sigBytes+=v,this},clamp:function(){var e=this.words,r=this.sigBytes;e[r>>>2]&=4294967295<<32-r%4*8,e.length=i.ceil(r/4);},clone:function(){var e=g.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var r=[],p=0;p<e;p+=4)r.push(n());return new x.init(r,e)}}),f=l.enc={},V=f.Hex={stringify:function(e){for(var r=e.words,p=e.sigBytes,c=[],v=0;v<p;v++){var P=r[v>>>2]>>>24-v%4*8&255;c.push((P>>>4).toString(16)),c.push((P&15).toString(16));}return c.join("")},parse:function(e){for(var r=e.length,p=[],c=0;c<r;c+=2)p[c>>>3]|=parseInt(e.substr(c,2),16)<<24-c%8*4;return new x.init(p,r/2)}},b=f.Latin1={stringify:function(e){for(var r=e.words,p=e.sigBytes,c=[],v=0;v<p;v++){var P=r[v>>>2]>>>24-v%4*8&255;c.push(String.fromCharCode(P));}return c.join("")},parse:function(e){for(var r=e.length,p=[],c=0;c<r;c++)p[c>>>2]|=(e.charCodeAt(c)&255)<<24-c%4*8;return new x.init(p,r)}},N=f.Utf8={stringify:function(e){try{return decodeURIComponent(escape(b.stringify(e)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(e){return b.parse(unescape(encodeURIComponent(e)))}},h=u.BufferedBlockAlgorithm=g.extend({reset:function(){this._data=new x.init,this._nDataBytes=0;},_append:function(e){typeof e=="string"&&(e=N.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes;},_process:function(e){var r,p=this._data,c=p.words,v=p.sigBytes,P=this.blockSize,k=P*4,L=v/k;e?L=i.ceil(L):L=i.max((L|0)-this._minBufferSize,0);var C=L*P,j=i.min(C*4,v);if(C){for(var E=0;E<C;E+=P)this._doProcessBlock(c,E);r=c.splice(0,C),p.sigBytes-=j;}return new x.init(r,j)},clone:function(){var e=g.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});u.Hasher=h.extend({cfg:g.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset();},reset:function(){h.reset.call(this),this._doReset();},update:function(e){return this._append(e),this._process(),this},finalize:function(e){e&&this._append(e);var r=this._doFinalize();return r},blockSize:512/32,_createHelper:function(e){return function(r,p){return new e.init(p).finalize(r)}},_createHmacHelper:function(e){return function(r,p){return new y.HMAC.init(e,p).finalize(r)}}});var y=l.algo={};return l})(Math);return a});});var M=R((B,F)=>{(function(a,i){typeof B=="object"?F.exports=B=i(q()):typeof define=="function"&&define.amd?define(["./core"],i):i(a.CryptoJS);})(B,function(a){return (function(){var i=a,t=i.lib,o=t.WordArray,n=t.Hasher,s=i.algo,l=[],u=s.SHA1=n.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(g,x){for(var f=this._hash.words,V=f[0],b=f[1],N=f[2],h=f[3],d=f[4],y=0;y<80;y++){if(y<16)l[y]=g[x+y]|0;else {var e=l[y-3]^l[y-8]^l[y-14]^l[y-16];l[y]=e<<1|e>>>31;}var r=(V<<5|V>>>27)+d+l[y];y<20?r+=(b&N|~b&h)+1518500249:y<40?r+=(b^N^h)+1859775393:y<60?r+=(b&N|b&h|N&h)-1894007588:r+=(b^N^h)-899497514,d=h,h=N,N=b<<30|b>>>2,b=V,V=r;}f[0]=f[0]+V|0,f[1]=f[1]+b|0,f[2]=f[2]+N|0,f[3]=f[3]+h|0,f[4]=f[4]+d|0;},_doFinalize:function(){var g=this._data,x=g.words,f=this._nDataBytes*8,V=g.sigBytes*8;return x[V>>>5]|=128<<24-V%32,x[(V+64>>>9<<4)+14]=Math.floor(f/4294967296),x[(V+64>>>9<<4)+15]=f,g.sigBytes=x.length*4,this._process(),this._hash},clone:function(){var g=n.clone.call(this);return g._hash=this._hash.clone(),g}});i.SHA1=n._createHelper(u),i.HmacSHA1=n._createHmacHelper(u);})(),a.SHA1});});function z(a){let i="";return a.values.forEach(t=>{if(typeof t=="string")i+=t;else {let o=core.JsonUnifier.getLogichValue(t);i+=`${o}`;}}),i}async function I(a,i){let t=core.JsonUnifier.getLogichValue(a);if(t)switch(t.type){case "sound":core.JsonUnifier.soundOperation(t);break;case "assets":case "bundle":await core.JsonUnifier.loadAssets(t);break;case "image":await core.JsonUnifier.imageOperation(t);break;case "video":await core.JsonUnifier.videoOperation(t);break;case "imagecontainer":await core.JsonUnifier.imageContainerOperation(t);break;case "text":await core.JsonUnifier.textOperation(t);break;case "canvaselement":await core.JsonUnifier.canvasElementOperation(t);break;case "value":core.JsonUnifier.setStorageValue(t);break;case "operationtoconvert":if(i){let o=z(t),n=await i(o);n&&await I(n,i);}break;case "input":case "dialogue":core.JsonUnifier.narrationOperation(t);break;case "shake":await core.JsonUnifier.effectOperation(t);break;case "animate":case "animate-sequence":core.JsonUnifier.animateOperation(t);break}}function W(a){let i=core.JsonUnifier.getLogichValue(a);i&&i.type==="value"&&i.storageOperationType==="set"&&(i.storageType==="storage"||i.storageType==="tempstorage")&&core.JsonUnifier.setInitialStorageValue(i);}var w;(n=>(n.log=(s,...l)=>console.log(`[Pixi\u2019VN Json] ${s}`,...l),n.warn=(s,...l)=>console.warn(`[Pixi\u2019VN Json] ${s}`,...l),n.error=(s,...l)=>console.error(`[Pixi\u2019VN Json] ${s}`,...l),n.info=(s,...l)=>console.info(`[Pixi\u2019VN Json] ${s}`,...l)))(w||(w={}));async function ae(a,i={}){if(!Array.isArray(a))if(typeof a=="object"||typeof a=="string")a=[a];else {w.error("Error parsing imported Pixi'VN JSON: data is not an object");return}let t=a.map(async s=>{if(typeof s=="string")try{s=JSON.parse(s);}catch(l){w.error("Error parsing imported Pixi'VN JSON",l),s={};}return s}),n=(await Promise.all(t)).map(async s=>{let l=[];if(s.initialOperations)for(let u of s.initialOperations)W(u);if(s.labels){let u=s.labels;for(let g in u)try{let x=u[g],f=new _(g,x,void 0,i);narration.RegisteredLabels.add(f);}catch(x){w.error(`Error creating JSON label ${g}`,x);}}return Promise.all(l)});await Promise.all(n);}var X=ne(M());var $="___param___";var _=class extends narration.LabelAbstract{constructor(t,o,n,s={}){n||(n={}),n.onLoadingLabel=async()=>{for(let l of o){let u;if(typeof l=="function"?u=l():u=l,u=core.JsonUnifier.getConditionalStep(u),u.operations)try{let g=u.operations.map(x=>core.JsonUnifier.loadAssets(x));await Promise.all(g);}catch(g){w.error("The operation in the onLoadingLabel function of the label has an error:",g);}}};super(t,n);T(this,"_steps");T(this,"operationStringConvert");T(this,"skipEmptyDialogs",false);this._steps=o,this.operationStringConvert=s.operationStringConvert,this.skipEmptyDialogs=s.skipEmptyDialogs||false;}get steps(){return this._steps.map(t=>this.stepConverter(t))}get stepCount(){return this._steps.length}getStepById(t){if(t<0||t>=this._steps.length)return;let o=this._steps[t];return this.stepConverter(o)}getStepSha(t){if(t<0||t>=this.steps.length)return;let o=this._steps[t];return (0, X.default)(o.toString().toLocaleLowerCase()).toString()}getDialogueText(t){let o="";if(Array.isArray(t)){let n=[];t.forEach(s=>{if(typeof s=="string")n.push(s);else if(s&&typeof s=="object"){let l=core.JsonUnifier.getLogichValue(s);l?(l&&!Array.isArray(l)&&typeof l=="object"&&(l=core.JsonUnifier.getLogichValue(l)||""),Array.isArray(l)?n=n.map(u=>`${u}`).concat(l):n.push(`${l}`)):n.push(`${s}`);}else n.push(`${s}`);}),o=n;}else {let n=core.JsonUnifier.getLogichValue(t);n&&!Array.isArray(n)&&typeof n=="object"&&(n=core.JsonUnifier.getLogichValue(n)),n&&Array.isArray(n)?o=n.map(s=>`${s}`):o=`${n}`;}return o}getDialogue(t){if(t==null)return;let o=core.JsonUnifier.getLogichValue(t);return o==null?`${o}`:typeof o=="object"&&"character"in o&&"text"in o?{character:o.character,text:translator.translator.t(this.getDialogueText(o.text))}:translator.translator.t(this.getDialogueText(o))}getChoices(t){return core.JsonUnifier.getLogichValue(t)?.map(s=>core.JsonUnifier.getLogichValue(s)).filter(s=>s!==void 0)}stepConverter(t){return async o=>{let n=typeof t=="function"?t():t;n=pixiVn.createExportableElement(n),n=core.JsonUnifier.getConditionalStep(n);let s=this.operationStringConvert?h=>this.operationStringConvert(h,n,o):void 0,{operations:l=[]}=n;for(let h of l)await I(h,s);let{labelToOpen:u=[]}=n,g=this.getChoices(n.choices),x=core.JsonUnifier.getLogichValue(n.glueEnabled),f=this.getDialogue(n.dialogue),V=[];Array.isArray(u)||(u=[u]),u.forEach(h=>{let d=core.JsonUnifier.getLogichValue(h);d&&V.push(d);});let b=core.JsonUnifier.getLogichValue(n.goNextStep),N=core.JsonUnifier.getLogichValue(n.end);if(g){let h=g.map(d=>{let y="";if(Array.isArray(d.text)){let r=[];d.text.forEach(p=>{if(typeof p=="string")r.push(translator.translator.t(p));else if(p&&typeof p=="object"){let c=core.JsonUnifier.getLogichValue(p);c&&!Array.isArray(c)&&typeof c=="object"&&(c=core.JsonUnifier.getLogichValue(c)||""),c&&(Array.isArray(c)?r=r.concat(translator.translator.t(c)):r.push(translator.translator.t(c)));}}),y=r;}else typeof d.text=="string"&&(y=translator.translator.t(d.text));return {label:d.label,text:y,props:d.props,type:d.type,oneTime:d.oneTime,onlyHaveNoChoice:d.onlyHaveNoChoice,autoSelect:d.autoSelect}});narration.narration.choices=h;}else narration.narration.choices=void 0;f!==void 0&&(narration.narration.dialogue=f,this.skipEmptyDialogs&&typeof f=="string"&&(f===""||RegExp(/^\s+$/).test(f))&&(b=true)),x?narration.narration.dialogGlue=true:x===false&&(narration.narration.dialogGlue=false);for(let h of V){let d=h.label;typeof d=="object"&&(d=core.JsonUnifier.getLogichValue(d)||"");let y=h.params?.map(e=>core.JsonUnifier.getLogichValue(e));o={...o,...h.props},h.type==="jump"?(narration.narration.openedLabels.length>0&&narration.narration.closeCurrentLabel(),storage.storage.setTempVariable(`${$}${narration.narration.openedLabels.length}`,y),await narration.narration.call(d,o)):(storage.storage.setTempVariable(`${$}${narration.narration.openedLabels.length}`,y),await narration.narration.call(d,o));}N==="game_end"?(narration.narration.closeAllLabels(),await narration.narration.continue(o,{runNow:true})):N==="label_end"&&narration.narration.closeCurrentLabel(),b&&await narration.narration.continue(o,{runNow:true});}}};exports.LabelJson=_;exports.importPixiVNJson=ae;
@@ -1,7 +1,7 @@
1
+ import { LabelAbstract, LabelProps, StepLabelPropsType as StepLabelPropsType$1, StepLabelType } from '@drincs/pixi-vn/narration';
1
2
  import { StorageElementType, CanvasBaseInterface, ImageSprite, ShakeEffectProps, ShowWithDissolveTransitionProps, ShowWithFadeTransitionProps, MoveInOutProps, ZoomInOutProps, PushInOutProps, ImageContainerOptions, ImageSpriteOptions, TextOptions, ImageSpriteMemory, VideoSpriteMemory, ImageContainerMemory, TextMemory, ContainerOptions, ContainerMemory, SoundPlayOptionsWithChannel, MediaInterface, LabelRunModeType, StorageObjectType, StepLabelPropsType } from '@drincs/pixi-vn';
2
3
  import { KeyframesType, AnimationOptions, ObjectSegment, ObjectSegmentWithTransition, SequenceOptions } from '@drincs/pixi-vn/motion';
3
4
  import { UPDATE_PRIORITY } from 'pixi.js';
4
- import { LabelAbstract, LabelProps, StepLabelPropsType as StepLabelPropsType$1, StepLabelType } from '@drincs/pixi-vn/narration';
5
5
 
6
6
  type PixiVNJsonStepSwitchElementType<Then> = Then | PixiVNJsonConditionalStatements<Then> | PixiVNJsonConditionalResultToCombine<Then>;
7
7
  type PixiVNJsonStepSwitchElementsType<Then> = PixiVNJsonStepSwitchElementType<Then>[] | PixiVNJsonConditionalStatements<Then[]>;
@@ -414,7 +414,7 @@ type PixiVNJsonSoundEdit = {
414
414
  type: "sound";
415
415
  operationType: "edit";
416
416
  alias: string;
417
- props: Partial<Pick<MediaInterface, "speed" | "volume" | "muted" | "loop" | "paused">>;
417
+ props: Partial<Pick<MediaInterface, "speed" | "muted" | "loop" | "paused"> & Pick<SoundPlayOptionsWithChannel, "volume">>;
418
418
  };
419
419
  type PixiVNJsonSound = PixiVNJsonSoundPlay | PixiVNJsonSoundRemove | PixiVNJsonSoundPauseResume | PixiVNJsonSoundEdit;
420
420
 
@@ -422,7 +422,12 @@ type PixiVNJsonOperationString = {
422
422
  type: "operationtoconvert";
423
423
  values: (string | PixiVNJsonValueGet | PixiVNJsonConditionalStatements<string | PixiVNJsonValueGet>)[];
424
424
  };
425
- type PixiVNJsonOperation = PixiVNJsonValueSet | PixiVNJsonCanvas | PixiVNJsonSound | PixiVNJsonNarration;
425
+ type PixiVNJsonOperation = (PixiVNJsonValueSet | PixiVNJsonCanvas | PixiVNJsonSound | PixiVNJsonNarration) & {
426
+ /**
427
+ * This value is used by the system to know where this operation is from, for example, if is generated from a string operation.
428
+ */
429
+ $origin?: string;
430
+ };
426
431
  type PixiVNJsonConditionalOperation = PixiVNJsonOperation | PixiVNJsonIfElse<PixiVNJsonOperation> | PixiVNJsonOperationString;
427
432
 
428
433
  type PixiVNJsonChoice = {
@@ -467,7 +472,7 @@ type PixiVNJsonDialog<Text = string> = {
467
472
  */
468
473
  text: Text;
469
474
  } | Text;
470
- type PixiVNJsonLabelToOpen<T extends {} = {}> = {
475
+ type PixiVNJsonLabelToOpen<T extends {} = object> = {
471
476
  /**
472
477
  * The id of the label to open.
473
478
  */
@@ -484,7 +489,7 @@ type PixiVNJsonLabelToOpen<T extends {} = {}> = {
484
489
  * **It is not recommended to use it, use it only if necessary**. The parameters to be passed to the label. If you want to pass an object, use the {@link PixiVNJsonLabelToOpen.props} attribute.
485
490
  * "params" attribute will be stored in the temp storage with the key: {@link PIXIVNJSON_PARAM_ID} + ({@link narration.openedLabels.length} - 1).
486
491
  */
487
- params?: any[];
492
+ params?: unknown[];
488
493
  };
489
494
  /**
490
495
  * Steps of a label.
@@ -555,13 +560,13 @@ type LabelJsonOptions = {
555
560
  * Function that converts a string to a {@link PixiVNJsonOperation}.
556
561
  * If is a special operation you can return undefined and can run the operation.
557
562
  */
558
- operationStringConvert?: (value: string, step: PixiVNJsonLabelStep, props: StepLabelPropsType$1 | {}) => Promise<PixiVNJsonOperation | undefined>;
563
+ operationStringConvert?: (value: string, step: PixiVNJsonLabelStep, props: StepLabelPropsType$1 | object) => Promise<PixiVNJsonOperation | undefined>;
559
564
  /**
560
565
  * If true and a dialog is empty or has only spaces, {@link PixiVNJsonLabelStep.goNextStep} will be set to true.
561
566
  */
562
567
  skipEmptyDialogs?: boolean;
563
568
  };
564
- declare class LabelJson<T extends {} = {}> extends LabelAbstract<LabelJson<T>, T> {
569
+ declare class LabelJson<T extends {} = object> extends LabelAbstract<LabelJson<T>, T> {
565
570
  /**
566
571
  * @param id is the id of the label
567
572
  * @param steps is the list of steps that the label will perform
@@ -1,7 +1,7 @@
1
+ import { LabelAbstract, LabelProps, StepLabelPropsType as StepLabelPropsType$1, StepLabelType } from '@drincs/pixi-vn/narration';
1
2
  import { StorageElementType, CanvasBaseInterface, ImageSprite, ShakeEffectProps, ShowWithDissolveTransitionProps, ShowWithFadeTransitionProps, MoveInOutProps, ZoomInOutProps, PushInOutProps, ImageContainerOptions, ImageSpriteOptions, TextOptions, ImageSpriteMemory, VideoSpriteMemory, ImageContainerMemory, TextMemory, ContainerOptions, ContainerMemory, SoundPlayOptionsWithChannel, MediaInterface, LabelRunModeType, StorageObjectType, StepLabelPropsType } from '@drincs/pixi-vn';
2
3
  import { KeyframesType, AnimationOptions, ObjectSegment, ObjectSegmentWithTransition, SequenceOptions } from '@drincs/pixi-vn/motion';
3
4
  import { UPDATE_PRIORITY } from 'pixi.js';
4
- import { LabelAbstract, LabelProps, StepLabelPropsType as StepLabelPropsType$1, StepLabelType } from '@drincs/pixi-vn/narration';
5
5
 
6
6
  type PixiVNJsonStepSwitchElementType<Then> = Then | PixiVNJsonConditionalStatements<Then> | PixiVNJsonConditionalResultToCombine<Then>;
7
7
  type PixiVNJsonStepSwitchElementsType<Then> = PixiVNJsonStepSwitchElementType<Then>[] | PixiVNJsonConditionalStatements<Then[]>;
@@ -414,7 +414,7 @@ type PixiVNJsonSoundEdit = {
414
414
  type: "sound";
415
415
  operationType: "edit";
416
416
  alias: string;
417
- props: Partial<Pick<MediaInterface, "speed" | "volume" | "muted" | "loop" | "paused">>;
417
+ props: Partial<Pick<MediaInterface, "speed" | "muted" | "loop" | "paused"> & Pick<SoundPlayOptionsWithChannel, "volume">>;
418
418
  };
419
419
  type PixiVNJsonSound = PixiVNJsonSoundPlay | PixiVNJsonSoundRemove | PixiVNJsonSoundPauseResume | PixiVNJsonSoundEdit;
420
420
 
@@ -422,7 +422,12 @@ type PixiVNJsonOperationString = {
422
422
  type: "operationtoconvert";
423
423
  values: (string | PixiVNJsonValueGet | PixiVNJsonConditionalStatements<string | PixiVNJsonValueGet>)[];
424
424
  };
425
- type PixiVNJsonOperation = PixiVNJsonValueSet | PixiVNJsonCanvas | PixiVNJsonSound | PixiVNJsonNarration;
425
+ type PixiVNJsonOperation = (PixiVNJsonValueSet | PixiVNJsonCanvas | PixiVNJsonSound | PixiVNJsonNarration) & {
426
+ /**
427
+ * This value is used by the system to know where this operation is from, for example, if is generated from a string operation.
428
+ */
429
+ $origin?: string;
430
+ };
426
431
  type PixiVNJsonConditionalOperation = PixiVNJsonOperation | PixiVNJsonIfElse<PixiVNJsonOperation> | PixiVNJsonOperationString;
427
432
 
428
433
  type PixiVNJsonChoice = {
@@ -467,7 +472,7 @@ type PixiVNJsonDialog<Text = string> = {
467
472
  */
468
473
  text: Text;
469
474
  } | Text;
470
- type PixiVNJsonLabelToOpen<T extends {} = {}> = {
475
+ type PixiVNJsonLabelToOpen<T extends {} = object> = {
471
476
  /**
472
477
  * The id of the label to open.
473
478
  */
@@ -484,7 +489,7 @@ type PixiVNJsonLabelToOpen<T extends {} = {}> = {
484
489
  * **It is not recommended to use it, use it only if necessary**. The parameters to be passed to the label. If you want to pass an object, use the {@link PixiVNJsonLabelToOpen.props} attribute.
485
490
  * "params" attribute will be stored in the temp storage with the key: {@link PIXIVNJSON_PARAM_ID} + ({@link narration.openedLabels.length} - 1).
486
491
  */
487
- params?: any[];
492
+ params?: unknown[];
488
493
  };
489
494
  /**
490
495
  * Steps of a label.
@@ -555,13 +560,13 @@ type LabelJsonOptions = {
555
560
  * Function that converts a string to a {@link PixiVNJsonOperation}.
556
561
  * If is a special operation you can return undefined and can run the operation.
557
562
  */
558
- operationStringConvert?: (value: string, step: PixiVNJsonLabelStep, props: StepLabelPropsType$1 | {}) => Promise<PixiVNJsonOperation | undefined>;
563
+ operationStringConvert?: (value: string, step: PixiVNJsonLabelStep, props: StepLabelPropsType$1 | object) => Promise<PixiVNJsonOperation | undefined>;
559
564
  /**
560
565
  * If true and a dialog is empty or has only spaces, {@link PixiVNJsonLabelStep.goNextStep} will be set to true.
561
566
  */
562
567
  skipEmptyDialogs?: boolean;
563
568
  };
564
- declare class LabelJson<T extends {} = {}> extends LabelAbstract<LabelJson<T>, T> {
569
+ declare class LabelJson<T extends {} = object> extends LabelAbstract<LabelJson<T>, T> {
565
570
  /**
566
571
  * @param id is the id of the label
567
572
  * @param steps is the list of steps that the label will perform
package/dist/importer.mjs CHANGED
@@ -1 +1 @@
1
- import {RegisteredLabels,LabelAbstract,narration}from'@drincs/pixi-vn/narration';import {JsonUnifier}from'@drincs/pixi-vn-json/core';import {createExportableElement}from'@drincs/pixi-vn';import {translator}from'@drincs/pixi-vn-json/translator';import {storage}from'@drincs/pixi-vn/storage';var K=Object.create;var E=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty;var te=(a,i,t)=>i in a?E(a,i,{enumerable:true,configurable:true,writable:true,value:t}):a[i]=t;var H=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(i,t)=>(typeof require<"u"?require:i)[t]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var R=(a,i)=>()=>(i||a((i={exports:{}}).exports,i),i.exports);var ie=(a,i,t,o)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of Y(i))!ee.call(a,n)&&n!==t&&E(a,n,{get:()=>i[n],enumerable:!(o=Q(i,n))||o.enumerable});return a};var ne=(a,i,t)=>(t=a!=null?K(Z(a)):{},ie(E(t,"default",{value:a,enumerable:true}),a));var T=(a,i,t)=>te(a,typeof i!="symbol"?i+"":i,t);var q=R((A,U)=>{(function(a,i){typeof A=="object"?U.exports=A=i():typeof define=="function"&&define.amd?define([],i):a.CryptoJS=i();})(A,function(){var a=a||(function(i,t){var o;if(typeof window<"u"&&window.crypto&&(o=window.crypto),typeof self<"u"&&self.crypto&&(o=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(o=globalThis.crypto),!o&&typeof window<"u"&&window.msCrypto&&(o=window.msCrypto),!o&&typeof global<"u"&&global.crypto&&(o=global.crypto),!o&&typeof H=="function")try{o=H("crypto");}catch{}var n=function(){if(o){if(typeof o.getRandomValues=="function")try{return o.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof o.randomBytes=="function")try{return o.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},s=Object.create||(function(){function e(){}return function(r){var f;return e.prototype=r,f=new e,e.prototype=null,f}})(),l={},u=l.lib={},g=u.Base=(function(){return {extend:function(e){var r=s(this);return e&&r.mixIn(e),(!r.hasOwnProperty("init")||this.init===r.init)&&(r.init=function(){r.$super.init.apply(this,arguments);}),r.init.prototype=r,r.$super=this,r},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var r in e)e.hasOwnProperty(r)&&(this[r]=e[r]);e.hasOwnProperty("toString")&&(this.toString=e.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),x=u.WordArray=g.extend({init:function(e,r){e=this.words=e||[],r!=t?this.sigBytes=r:this.sigBytes=e.length*4;},toString:function(e){return (e||V).stringify(this)},concat:function(e){var r=this.words,f=e.words,c=this.sigBytes,v=e.sigBytes;if(this.clamp(),c%4)for(var P=0;P<v;P++){var k=f[P>>>2]>>>24-P%4*8&255;r[c+P>>>2]|=k<<24-(c+P)%4*8;}else for(var L=0;L<v;L+=4)r[c+L>>>2]=f[L>>>2];return this.sigBytes+=v,this},clamp:function(){var e=this.words,r=this.sigBytes;e[r>>>2]&=4294967295<<32-r%4*8,e.length=i.ceil(r/4);},clone:function(){var e=g.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var r=[],f=0;f<e;f+=4)r.push(n());return new x.init(r,e)}}),p=l.enc={},V=p.Hex={stringify:function(e){for(var r=e.words,f=e.sigBytes,c=[],v=0;v<f;v++){var P=r[v>>>2]>>>24-v%4*8&255;c.push((P>>>4).toString(16)),c.push((P&15).toString(16));}return c.join("")},parse:function(e){for(var r=e.length,f=[],c=0;c<r;c+=2)f[c>>>3]|=parseInt(e.substr(c,2),16)<<24-c%8*4;return new x.init(f,r/2)}},b=p.Latin1={stringify:function(e){for(var r=e.words,f=e.sigBytes,c=[],v=0;v<f;v++){var P=r[v>>>2]>>>24-v%4*8&255;c.push(String.fromCharCode(P));}return c.join("")},parse:function(e){for(var r=e.length,f=[],c=0;c<r;c++)f[c>>>2]|=(e.charCodeAt(c)&255)<<24-c%4*8;return new x.init(f,r)}},N=p.Utf8={stringify:function(e){try{return decodeURIComponent(escape(b.stringify(e)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(e){return b.parse(unescape(encodeURIComponent(e)))}},h=u.BufferedBlockAlgorithm=g.extend({reset:function(){this._data=new x.init,this._nDataBytes=0;},_append:function(e){typeof e=="string"&&(e=N.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes;},_process:function(e){var r,f=this._data,c=f.words,v=f.sigBytes,P=this.blockSize,k=P*4,L=v/k;e?L=i.ceil(L):L=i.max((L|0)-this._minBufferSize,0);var C=L*P,j=i.min(C*4,v);if(C){for(var D=0;D<C;D+=P)this._doProcessBlock(c,D);r=c.splice(0,C),f.sigBytes-=j;}return new x.init(r,j)},clone:function(){var e=g.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});u.Hasher=h.extend({cfg:g.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset();},reset:function(){h.reset.call(this),this._doReset();},update:function(e){return this._append(e),this._process(),this},finalize:function(e){e&&this._append(e);var r=this._doFinalize();return r},blockSize:512/32,_createHelper:function(e){return function(r,f){return new e.init(f).finalize(r)}},_createHmacHelper:function(e){return function(r,f){return new y.HMAC.init(e,f).finalize(r)}}});var y=l.algo={};return l})(Math);return a});});var M=R((B,F)=>{(function(a,i){typeof B=="object"?F.exports=B=i(q()):typeof define=="function"&&define.amd?define(["./core"],i):i(a.CryptoJS);})(B,function(a){return (function(){var i=a,t=i.lib,o=t.WordArray,n=t.Hasher,s=i.algo,l=[],u=s.SHA1=n.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(g,x){for(var p=this._hash.words,V=p[0],b=p[1],N=p[2],h=p[3],d=p[4],y=0;y<80;y++){if(y<16)l[y]=g[x+y]|0;else {var e=l[y-3]^l[y-8]^l[y-14]^l[y-16];l[y]=e<<1|e>>>31;}var r=(V<<5|V>>>27)+d+l[y];y<20?r+=(b&N|~b&h)+1518500249:y<40?r+=(b^N^h)+1859775393:y<60?r+=(b&N|b&h|N&h)-1894007588:r+=(b^N^h)-899497514,d=h,h=N,N=b<<30|b>>>2,b=V,V=r;}p[0]=p[0]+V|0,p[1]=p[1]+b|0,p[2]=p[2]+N|0,p[3]=p[3]+h|0,p[4]=p[4]+d|0;},_doFinalize:function(){var g=this._data,x=g.words,p=this._nDataBytes*8,V=g.sigBytes*8;return x[V>>>5]|=128<<24-V%32,x[(V+64>>>9<<4)+14]=Math.floor(p/4294967296),x[(V+64>>>9<<4)+15]=p,g.sigBytes=x.length*4,this._process(),this._hash},clone:function(){var g=n.clone.call(this);return g._hash=this._hash.clone(),g}});i.SHA1=n._createHelper(u),i.HmacSHA1=n._createHmacHelper(u);})(),a.SHA1});});var w;(n=>(n.log=(s,...l)=>console.log(`[Pixi\u2019VN Json] ${s}`,...l),n.warn=(s,...l)=>console.warn(`[Pixi\u2019VN Json] ${s}`,...l),n.error=(s,...l)=>console.error(`[Pixi\u2019VN Json] ${s}`,...l),n.info=(s,...l)=>console.info(`[Pixi\u2019VN Json] ${s}`,...l)))(w||(w={}));function z(a){let i="";return a.values.forEach(t=>{if(typeof t=="string")i+=t;else {let o=JsonUnifier.getLogichValue(t);i+=`${o}`;}}),i}async function I(a,i){let t=JsonUnifier.getLogichValue(a);if(t)switch(t.type){case "sound":JsonUnifier.soundOperation(t);break;case "assets":case "bundle":await JsonUnifier.loadAssets(t);break;case "image":await JsonUnifier.imageOperation(t);break;case "video":await JsonUnifier.videoOperation(t);break;case "imagecontainer":await JsonUnifier.imageContainerOperation(t);break;case "text":await JsonUnifier.textOperation(t);break;case "canvaselement":await JsonUnifier.canvasElementOperation(t);break;case "value":JsonUnifier.setStorageValue(t);break;case "operationtoconvert":if(i){let o=z(t),n=await i(o);n&&await I(n,i);}break;case "input":case "dialogue":JsonUnifier.narrationOperation(t);break;case "shake":await JsonUnifier.effectOperation(t);break;case "animate":case "animate-sequence":JsonUnifier.animateOperation(t);break}}function W(a){let i=JsonUnifier.getLogichValue(a);i&&i.type==="value"&&i.storageOperationType==="set"&&(i.storageType==="storage"||i.storageType==="tempstorage")&&JsonUnifier.setInitialStorageValue(i);}async function ae(a,i={}){if(!Array.isArray(a))if(typeof a=="object"||typeof a=="string")a=[a];else {w.error("Error parsing imported Pixi'VN JSON: data is not an object");return}let t=a.map(async s=>{if(typeof s=="string")try{s=JSON.parse(s);}catch(l){w.error("Error parsing imported Pixi'VN JSON",l),s={};}return s}),n=(await Promise.all(t)).map(async s=>{let l=[];if(s.initialOperations)for(let u of s.initialOperations)W(u);if(s.labels){let u=s.labels;for(let g in u)try{let x=u[g],p=new _(g,x,void 0,i);RegisteredLabels.add(p);}catch(x){w.error(`Error creating JSON label ${g}`,x);}}return Promise.all(l)});await Promise.all(n);}var X=ne(M());var $="___param___";var _=class extends LabelAbstract{constructor(t,o,n,s={}){n||(n={}),n.onLoadingLabel=async()=>{for(let l of o){let u;if(typeof l=="function"?u=l():u=l,u=JsonUnifier.getConditionalStep(u),u.operations)try{let g=u.operations.map(x=>JsonUnifier.loadAssets(x));await Promise.all(g);}catch(g){w.error("The operation in the onLoadingLabel function of the label has an error:",g);}}};super(t,n);T(this,"_steps");T(this,"operationStringConvert");T(this,"skipEmptyDialogs",false);this._steps=o,this.operationStringConvert=s.operationStringConvert,this.skipEmptyDialogs=s.skipEmptyDialogs||false;}get steps(){return this._steps.map(t=>this.stepConverter(t))}get stepCount(){return this._steps.length}getStepById(t){if(t<0||t>=this._steps.length)return;let o=this._steps[t];return this.stepConverter(o)}getStepSha(t){if(t<0||t>=this.steps.length)return;let o=this._steps[t];return (0, X.default)(o.toString().toLocaleLowerCase()).toString()}getDialogueText(t){let o="";if(Array.isArray(t)){let n=[];t.forEach(s=>{if(typeof s=="string")n.push(s);else if(s&&typeof s=="object"){let l=JsonUnifier.getLogichValue(s);l?(l&&!Array.isArray(l)&&typeof l=="object"&&(l=JsonUnifier.getLogichValue(l)||""),Array.isArray(l)?n=n.map(u=>`${u}`).concat(l):n.push(`${l}`)):n.push(`${s}`);}else n.push(`${s}`);}),o=n;}else {let n=JsonUnifier.getLogichValue(t);n&&!Array.isArray(n)&&typeof n=="object"&&(n=JsonUnifier.getLogichValue(n)),n&&Array.isArray(n)?o=n.map(s=>`${s}`):o=`${n}`;}return o}getDialogue(t){if(t==null)return;let o=JsonUnifier.getLogichValue(t);return o==null?`${o}`:typeof o=="object"&&"character"in o&&"text"in o?{character:o.character,text:translator.t(this.getDialogueText(o.text))}:translator.t(this.getDialogueText(o))}getChoices(t){return JsonUnifier.getLogichValue(t)?.map(s=>JsonUnifier.getLogichValue(s)).filter(s=>s!==void 0)}stepConverter(t){return async o=>{let n=typeof t=="function"?t():t;n=createExportableElement(n),n=JsonUnifier.getConditionalStep(n);let s=this.operationStringConvert?h=>this.operationStringConvert(h,n,o):void 0,{operations:l=[]}=n;for(let h of l)await I(h,s);let{labelToOpen:u=[]}=n,g=this.getChoices(n.choices),x=JsonUnifier.getLogichValue(n.glueEnabled),p=this.getDialogue(n.dialogue),V=[];Array.isArray(u)||(u=[u]),u.forEach(h=>{let d=JsonUnifier.getLogichValue(h);d&&V.push(d);});let b=JsonUnifier.getLogichValue(n.goNextStep),N=JsonUnifier.getLogichValue(n.end);if(g){let h=g.map(d=>{let y="";if(Array.isArray(d.text)){let r=[];d.text.forEach(f=>{if(typeof f=="string")r.push(translator.t(f));else if(f&&typeof f=="object"){let c=JsonUnifier.getLogichValue(f);c&&!Array.isArray(c)&&typeof c=="object"&&(c=JsonUnifier.getLogichValue(c)||""),c&&(Array.isArray(c)?r=r.concat(translator.t(c)):r.push(translator.t(c)));}}),y=r;}else typeof d.text=="string"&&(y=translator.t(d.text));return {label:d.label,text:y,props:d.props,type:d.type,oneTime:d.oneTime,onlyHaveNoChoice:d.onlyHaveNoChoice,autoSelect:d.autoSelect}});narration.choices=h;}else narration.choices=void 0;p!==void 0&&(narration.dialogue=p,this.skipEmptyDialogs&&typeof p=="string"&&(p===""||RegExp(/^\s+$/).test(p))&&(b=true)),x?narration.dialogGlue=true:x===false&&(narration.dialogGlue=false);for(let h of V){let d=h.label;typeof d=="object"&&(d=JsonUnifier.getLogichValue(d)||"");let y=h.params?.map(e=>JsonUnifier.getLogichValue(e));o={...o,...h.props},h.type==="jump"?(narration.openedLabels.length>0&&narration.closeCurrentLabel(),storage.setTempVariable(`${$}${narration.openedLabels.length}`,y),await narration.call(d,o)):(storage.setTempVariable(`${$}${narration.openedLabels.length}`,y),await narration.call(d,o));}N==="game_end"?(narration.closeAllLabels(),await narration.continue(o,{runNow:true})):N==="label_end"&&narration.closeCurrentLabel(),b&&await narration.continue(o,{runNow:true});}}};export{_ as LabelJson,ae as importPixiVNJson};
1
+ import {JsonUnifier}from'@drincs/pixi-vn-json/core';import {RegisteredLabels,LabelAbstract,narration}from'@drincs/pixi-vn/narration';import {createExportableElement}from'@drincs/pixi-vn';import {translator}from'@drincs/pixi-vn-json/translator';import {storage}from'@drincs/pixi-vn/storage';var K=Object.create;var D=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty;var te=(a,i,t)=>i in a?D(a,i,{enumerable:true,configurable:true,writable:true,value:t}):a[i]=t;var H=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(i,t)=>(typeof require<"u"?require:i)[t]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var R=(a,i)=>()=>(i||a((i={exports:{}}).exports,i),i.exports);var ie=(a,i,t,o)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of Y(i))!ee.call(a,n)&&n!==t&&D(a,n,{get:()=>i[n],enumerable:!(o=Q(i,n))||o.enumerable});return a};var ne=(a,i,t)=>(t=a!=null?K(Z(a)):{},ie(D(t,"default",{value:a,enumerable:true}),a));var T=(a,i,t)=>te(a,typeof i!="symbol"?i+"":i,t);var q=R((A,U)=>{(function(a,i){typeof A=="object"?U.exports=A=i():typeof define=="function"&&define.amd?define([],i):a.CryptoJS=i();})(A,function(){var a=a||(function(i,t){var o;if(typeof window<"u"&&window.crypto&&(o=window.crypto),typeof self<"u"&&self.crypto&&(o=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(o=globalThis.crypto),!o&&typeof window<"u"&&window.msCrypto&&(o=window.msCrypto),!o&&typeof global<"u"&&global.crypto&&(o=global.crypto),!o&&typeof H=="function")try{o=H("crypto");}catch{}var n=function(){if(o){if(typeof o.getRandomValues=="function")try{return o.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof o.randomBytes=="function")try{return o.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},s=Object.create||(function(){function e(){}return function(r){var p;return e.prototype=r,p=new e,e.prototype=null,p}})(),l={},u=l.lib={},g=u.Base=(function(){return {extend:function(e){var r=s(this);return e&&r.mixIn(e),(!r.hasOwnProperty("init")||this.init===r.init)&&(r.init=function(){r.$super.init.apply(this,arguments);}),r.init.prototype=r,r.$super=this,r},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var r in e)e.hasOwnProperty(r)&&(this[r]=e[r]);e.hasOwnProperty("toString")&&(this.toString=e.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),x=u.WordArray=g.extend({init:function(e,r){e=this.words=e||[],r!=t?this.sigBytes=r:this.sigBytes=e.length*4;},toString:function(e){return (e||V).stringify(this)},concat:function(e){var r=this.words,p=e.words,c=this.sigBytes,v=e.sigBytes;if(this.clamp(),c%4)for(var P=0;P<v;P++){var k=p[P>>>2]>>>24-P%4*8&255;r[c+P>>>2]|=k<<24-(c+P)%4*8;}else for(var L=0;L<v;L+=4)r[c+L>>>2]=p[L>>>2];return this.sigBytes+=v,this},clamp:function(){var e=this.words,r=this.sigBytes;e[r>>>2]&=4294967295<<32-r%4*8,e.length=i.ceil(r/4);},clone:function(){var e=g.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var r=[],p=0;p<e;p+=4)r.push(n());return new x.init(r,e)}}),f=l.enc={},V=f.Hex={stringify:function(e){for(var r=e.words,p=e.sigBytes,c=[],v=0;v<p;v++){var P=r[v>>>2]>>>24-v%4*8&255;c.push((P>>>4).toString(16)),c.push((P&15).toString(16));}return c.join("")},parse:function(e){for(var r=e.length,p=[],c=0;c<r;c+=2)p[c>>>3]|=parseInt(e.substr(c,2),16)<<24-c%8*4;return new x.init(p,r/2)}},b=f.Latin1={stringify:function(e){for(var r=e.words,p=e.sigBytes,c=[],v=0;v<p;v++){var P=r[v>>>2]>>>24-v%4*8&255;c.push(String.fromCharCode(P));}return c.join("")},parse:function(e){for(var r=e.length,p=[],c=0;c<r;c++)p[c>>>2]|=(e.charCodeAt(c)&255)<<24-c%4*8;return new x.init(p,r)}},N=f.Utf8={stringify:function(e){try{return decodeURIComponent(escape(b.stringify(e)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(e){return b.parse(unescape(encodeURIComponent(e)))}},h=u.BufferedBlockAlgorithm=g.extend({reset:function(){this._data=new x.init,this._nDataBytes=0;},_append:function(e){typeof e=="string"&&(e=N.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes;},_process:function(e){var r,p=this._data,c=p.words,v=p.sigBytes,P=this.blockSize,k=P*4,L=v/k;e?L=i.ceil(L):L=i.max((L|0)-this._minBufferSize,0);var C=L*P,j=i.min(C*4,v);if(C){for(var E=0;E<C;E+=P)this._doProcessBlock(c,E);r=c.splice(0,C),p.sigBytes-=j;}return new x.init(r,j)},clone:function(){var e=g.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});u.Hasher=h.extend({cfg:g.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset();},reset:function(){h.reset.call(this),this._doReset();},update:function(e){return this._append(e),this._process(),this},finalize:function(e){e&&this._append(e);var r=this._doFinalize();return r},blockSize:512/32,_createHelper:function(e){return function(r,p){return new e.init(p).finalize(r)}},_createHmacHelper:function(e){return function(r,p){return new y.HMAC.init(e,p).finalize(r)}}});var y=l.algo={};return l})(Math);return a});});var M=R((B,F)=>{(function(a,i){typeof B=="object"?F.exports=B=i(q()):typeof define=="function"&&define.amd?define(["./core"],i):i(a.CryptoJS);})(B,function(a){return (function(){var i=a,t=i.lib,o=t.WordArray,n=t.Hasher,s=i.algo,l=[],u=s.SHA1=n.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(g,x){for(var f=this._hash.words,V=f[0],b=f[1],N=f[2],h=f[3],d=f[4],y=0;y<80;y++){if(y<16)l[y]=g[x+y]|0;else {var e=l[y-3]^l[y-8]^l[y-14]^l[y-16];l[y]=e<<1|e>>>31;}var r=(V<<5|V>>>27)+d+l[y];y<20?r+=(b&N|~b&h)+1518500249:y<40?r+=(b^N^h)+1859775393:y<60?r+=(b&N|b&h|N&h)-1894007588:r+=(b^N^h)-899497514,d=h,h=N,N=b<<30|b>>>2,b=V,V=r;}f[0]=f[0]+V|0,f[1]=f[1]+b|0,f[2]=f[2]+N|0,f[3]=f[3]+h|0,f[4]=f[4]+d|0;},_doFinalize:function(){var g=this._data,x=g.words,f=this._nDataBytes*8,V=g.sigBytes*8;return x[V>>>5]|=128<<24-V%32,x[(V+64>>>9<<4)+14]=Math.floor(f/4294967296),x[(V+64>>>9<<4)+15]=f,g.sigBytes=x.length*4,this._process(),this._hash},clone:function(){var g=n.clone.call(this);return g._hash=this._hash.clone(),g}});i.SHA1=n._createHelper(u),i.HmacSHA1=n._createHmacHelper(u);})(),a.SHA1});});function z(a){let i="";return a.values.forEach(t=>{if(typeof t=="string")i+=t;else {let o=JsonUnifier.getLogichValue(t);i+=`${o}`;}}),i}async function I(a,i){let t=JsonUnifier.getLogichValue(a);if(t)switch(t.type){case "sound":JsonUnifier.soundOperation(t);break;case "assets":case "bundle":await JsonUnifier.loadAssets(t);break;case "image":await JsonUnifier.imageOperation(t);break;case "video":await JsonUnifier.videoOperation(t);break;case "imagecontainer":await JsonUnifier.imageContainerOperation(t);break;case "text":await JsonUnifier.textOperation(t);break;case "canvaselement":await JsonUnifier.canvasElementOperation(t);break;case "value":JsonUnifier.setStorageValue(t);break;case "operationtoconvert":if(i){let o=z(t),n=await i(o);n&&await I(n,i);}break;case "input":case "dialogue":JsonUnifier.narrationOperation(t);break;case "shake":await JsonUnifier.effectOperation(t);break;case "animate":case "animate-sequence":JsonUnifier.animateOperation(t);break}}function W(a){let i=JsonUnifier.getLogichValue(a);i&&i.type==="value"&&i.storageOperationType==="set"&&(i.storageType==="storage"||i.storageType==="tempstorage")&&JsonUnifier.setInitialStorageValue(i);}var w;(n=>(n.log=(s,...l)=>console.log(`[Pixi\u2019VN Json] ${s}`,...l),n.warn=(s,...l)=>console.warn(`[Pixi\u2019VN Json] ${s}`,...l),n.error=(s,...l)=>console.error(`[Pixi\u2019VN Json] ${s}`,...l),n.info=(s,...l)=>console.info(`[Pixi\u2019VN Json] ${s}`,...l)))(w||(w={}));async function ae(a,i={}){if(!Array.isArray(a))if(typeof a=="object"||typeof a=="string")a=[a];else {w.error("Error parsing imported Pixi'VN JSON: data is not an object");return}let t=a.map(async s=>{if(typeof s=="string")try{s=JSON.parse(s);}catch(l){w.error("Error parsing imported Pixi'VN JSON",l),s={};}return s}),n=(await Promise.all(t)).map(async s=>{let l=[];if(s.initialOperations)for(let u of s.initialOperations)W(u);if(s.labels){let u=s.labels;for(let g in u)try{let x=u[g],f=new _(g,x,void 0,i);RegisteredLabels.add(f);}catch(x){w.error(`Error creating JSON label ${g}`,x);}}return Promise.all(l)});await Promise.all(n);}var X=ne(M());var $="___param___";var _=class extends LabelAbstract{constructor(t,o,n,s={}){n||(n={}),n.onLoadingLabel=async()=>{for(let l of o){let u;if(typeof l=="function"?u=l():u=l,u=JsonUnifier.getConditionalStep(u),u.operations)try{let g=u.operations.map(x=>JsonUnifier.loadAssets(x));await Promise.all(g);}catch(g){w.error("The operation in the onLoadingLabel function of the label has an error:",g);}}};super(t,n);T(this,"_steps");T(this,"operationStringConvert");T(this,"skipEmptyDialogs",false);this._steps=o,this.operationStringConvert=s.operationStringConvert,this.skipEmptyDialogs=s.skipEmptyDialogs||false;}get steps(){return this._steps.map(t=>this.stepConverter(t))}get stepCount(){return this._steps.length}getStepById(t){if(t<0||t>=this._steps.length)return;let o=this._steps[t];return this.stepConverter(o)}getStepSha(t){if(t<0||t>=this.steps.length)return;let o=this._steps[t];return (0, X.default)(o.toString().toLocaleLowerCase()).toString()}getDialogueText(t){let o="";if(Array.isArray(t)){let n=[];t.forEach(s=>{if(typeof s=="string")n.push(s);else if(s&&typeof s=="object"){let l=JsonUnifier.getLogichValue(s);l?(l&&!Array.isArray(l)&&typeof l=="object"&&(l=JsonUnifier.getLogichValue(l)||""),Array.isArray(l)?n=n.map(u=>`${u}`).concat(l):n.push(`${l}`)):n.push(`${s}`);}else n.push(`${s}`);}),o=n;}else {let n=JsonUnifier.getLogichValue(t);n&&!Array.isArray(n)&&typeof n=="object"&&(n=JsonUnifier.getLogichValue(n)),n&&Array.isArray(n)?o=n.map(s=>`${s}`):o=`${n}`;}return o}getDialogue(t){if(t==null)return;let o=JsonUnifier.getLogichValue(t);return o==null?`${o}`:typeof o=="object"&&"character"in o&&"text"in o?{character:o.character,text:translator.t(this.getDialogueText(o.text))}:translator.t(this.getDialogueText(o))}getChoices(t){return JsonUnifier.getLogichValue(t)?.map(s=>JsonUnifier.getLogichValue(s)).filter(s=>s!==void 0)}stepConverter(t){return async o=>{let n=typeof t=="function"?t():t;n=createExportableElement(n),n=JsonUnifier.getConditionalStep(n);let s=this.operationStringConvert?h=>this.operationStringConvert(h,n,o):void 0,{operations:l=[]}=n;for(let h of l)await I(h,s);let{labelToOpen:u=[]}=n,g=this.getChoices(n.choices),x=JsonUnifier.getLogichValue(n.glueEnabled),f=this.getDialogue(n.dialogue),V=[];Array.isArray(u)||(u=[u]),u.forEach(h=>{let d=JsonUnifier.getLogichValue(h);d&&V.push(d);});let b=JsonUnifier.getLogichValue(n.goNextStep),N=JsonUnifier.getLogichValue(n.end);if(g){let h=g.map(d=>{let y="";if(Array.isArray(d.text)){let r=[];d.text.forEach(p=>{if(typeof p=="string")r.push(translator.t(p));else if(p&&typeof p=="object"){let c=JsonUnifier.getLogichValue(p);c&&!Array.isArray(c)&&typeof c=="object"&&(c=JsonUnifier.getLogichValue(c)||""),c&&(Array.isArray(c)?r=r.concat(translator.t(c)):r.push(translator.t(c)));}}),y=r;}else typeof d.text=="string"&&(y=translator.t(d.text));return {label:d.label,text:y,props:d.props,type:d.type,oneTime:d.oneTime,onlyHaveNoChoice:d.onlyHaveNoChoice,autoSelect:d.autoSelect}});narration.choices=h;}else narration.choices=void 0;f!==void 0&&(narration.dialogue=f,this.skipEmptyDialogs&&typeof f=="string"&&(f===""||RegExp(/^\s+$/).test(f))&&(b=true)),x?narration.dialogGlue=true:x===false&&(narration.dialogGlue=false);for(let h of V){let d=h.label;typeof d=="object"&&(d=JsonUnifier.getLogichValue(d)||"");let y=h.params?.map(e=>JsonUnifier.getLogichValue(e));o={...o,...h.props},h.type==="jump"?(narration.openedLabels.length>0&&narration.closeCurrentLabel(),storage.setTempVariable(`${$}${narration.openedLabels.length}`,y),await narration.call(d,o)):(storage.setTempVariable(`${$}${narration.openedLabels.length}`,y),await narration.call(d,o));}N==="game_end"?(narration.closeAllLabels(),await narration.continue(o,{runNow:true})):N==="label_end"&&narration.closeCurrentLabel(),b&&await narration.continue(o,{runNow:true});}}};export{_ as LabelJson,ae as importPixiVNJson};
package/dist/index.d.cts CHANGED
@@ -418,7 +418,7 @@ type PixiVNJsonSoundEdit = {
418
418
  type: "sound";
419
419
  operationType: "edit";
420
420
  alias: string;
421
- props: Partial<Pick<MediaInterface, "speed" | "volume" | "muted" | "loop" | "paused">>;
421
+ props: Partial<Pick<MediaInterface, "speed" | "muted" | "loop" | "paused"> & Pick<SoundPlayOptionsWithChannel, "volume">>;
422
422
  };
423
423
  type PixiVNJsonSound = PixiVNJsonSoundPlay | PixiVNJsonSoundRemove | PixiVNJsonSoundPauseResume | PixiVNJsonSoundEdit;
424
424
 
@@ -426,7 +426,12 @@ type PixiVNJsonOperationString = {
426
426
  type: "operationtoconvert";
427
427
  values: (string | PixiVNJsonValueGet | PixiVNJsonConditionalStatements<string | PixiVNJsonValueGet>)[];
428
428
  };
429
- type PixiVNJsonOperation = PixiVNJsonValueSet | PixiVNJsonCanvas | PixiVNJsonSound | PixiVNJsonNarration;
429
+ type PixiVNJsonOperation = (PixiVNJsonValueSet | PixiVNJsonCanvas | PixiVNJsonSound | PixiVNJsonNarration) & {
430
+ /**
431
+ * This value is used by the system to know where this operation is from, for example, if is generated from a string operation.
432
+ */
433
+ $origin?: string;
434
+ };
430
435
  type PixiVNJsonConditionalOperation = PixiVNJsonOperation | PixiVNJsonIfElse<PixiVNJsonOperation> | PixiVNJsonOperationString;
431
436
 
432
437
  type PixiVNJsonChoice = {
@@ -471,7 +476,7 @@ type PixiVNJsonDialog<Text = string> = {
471
476
  */
472
477
  text: Text;
473
478
  } | Text;
474
- type PixiVNJsonLabelToOpen<T extends {} = {}> = {
479
+ type PixiVNJsonLabelToOpen<T extends {} = object> = {
475
480
  /**
476
481
  * The id of the label to open.
477
482
  */
@@ -488,7 +493,7 @@ type PixiVNJsonLabelToOpen<T extends {} = {}> = {
488
493
  * **It is not recommended to use it, use it only if necessary**. The parameters to be passed to the label. If you want to pass an object, use the {@link PixiVNJsonLabelToOpen.props} attribute.
489
494
  * "params" attribute will be stored in the temp storage with the key: {@link PIXIVNJSON_PARAM_ID} + ({@link narration.openedLabels.length} - 1).
490
495
  */
491
- params?: any[];
496
+ params?: unknown[];
492
497
  };
493
498
  /**
494
499
  * Steps of a label.
package/dist/index.d.ts CHANGED
@@ -418,7 +418,7 @@ type PixiVNJsonSoundEdit = {
418
418
  type: "sound";
419
419
  operationType: "edit";
420
420
  alias: string;
421
- props: Partial<Pick<MediaInterface, "speed" | "volume" | "muted" | "loop" | "paused">>;
421
+ props: Partial<Pick<MediaInterface, "speed" | "muted" | "loop" | "paused"> & Pick<SoundPlayOptionsWithChannel, "volume">>;
422
422
  };
423
423
  type PixiVNJsonSound = PixiVNJsonSoundPlay | PixiVNJsonSoundRemove | PixiVNJsonSoundPauseResume | PixiVNJsonSoundEdit;
424
424
 
@@ -426,7 +426,12 @@ type PixiVNJsonOperationString = {
426
426
  type: "operationtoconvert";
427
427
  values: (string | PixiVNJsonValueGet | PixiVNJsonConditionalStatements<string | PixiVNJsonValueGet>)[];
428
428
  };
429
- type PixiVNJsonOperation = PixiVNJsonValueSet | PixiVNJsonCanvas | PixiVNJsonSound | PixiVNJsonNarration;
429
+ type PixiVNJsonOperation = (PixiVNJsonValueSet | PixiVNJsonCanvas | PixiVNJsonSound | PixiVNJsonNarration) & {
430
+ /**
431
+ * This value is used by the system to know where this operation is from, for example, if is generated from a string operation.
432
+ */
433
+ $origin?: string;
434
+ };
430
435
  type PixiVNJsonConditionalOperation = PixiVNJsonOperation | PixiVNJsonIfElse<PixiVNJsonOperation> | PixiVNJsonOperationString;
431
436
 
432
437
  type PixiVNJsonChoice = {
@@ -471,7 +476,7 @@ type PixiVNJsonDialog<Text = string> = {
471
476
  */
472
477
  text: Text;
473
478
  } | Text;
474
- type PixiVNJsonLabelToOpen<T extends {} = {}> = {
479
+ type PixiVNJsonLabelToOpen<T extends {} = object> = {
475
480
  /**
476
481
  * The id of the label to open.
477
482
  */
@@ -488,7 +493,7 @@ type PixiVNJsonLabelToOpen<T extends {} = {}> = {
488
493
  * **It is not recommended to use it, use it only if necessary**. The parameters to be passed to the label. If you want to pass an object, use the {@link PixiVNJsonLabelToOpen.props} attribute.
489
494
  * "params" attribute will be stored in the temp storage with the key: {@link PIXIVNJSON_PARAM_ID} + ({@link narration.openedLabels.length} - 1).
490
495
  */
491
- params?: any[];
496
+ params?: unknown[];
492
497
  };
493
498
  /**
494
499
  * Steps of a label.
@@ -413,7 +413,7 @@ type PixiVNJsonSoundEdit = {
413
413
  type: "sound";
414
414
  operationType: "edit";
415
415
  alias: string;
416
- props: Partial<Pick<MediaInterface, "speed" | "volume" | "muted" | "loop" | "paused">>;
416
+ props: Partial<Pick<MediaInterface, "speed" | "muted" | "loop" | "paused"> & Pick<SoundPlayOptionsWithChannel, "volume">>;
417
417
  };
418
418
  type PixiVNJsonSound = PixiVNJsonSoundPlay | PixiVNJsonSoundRemove | PixiVNJsonSoundPauseResume | PixiVNJsonSoundEdit;
419
419
 
@@ -421,7 +421,12 @@ type PixiVNJsonOperationString = {
421
421
  type: "operationtoconvert";
422
422
  values: (string | PixiVNJsonValueGet | PixiVNJsonConditionalStatements<string | PixiVNJsonValueGet>)[];
423
423
  };
424
- type PixiVNJsonOperation = PixiVNJsonValueSet | PixiVNJsonCanvas | PixiVNJsonSound | PixiVNJsonNarration;
424
+ type PixiVNJsonOperation = (PixiVNJsonValueSet | PixiVNJsonCanvas | PixiVNJsonSound | PixiVNJsonNarration) & {
425
+ /**
426
+ * This value is used by the system to know where this operation is from, for example, if is generated from a string operation.
427
+ */
428
+ $origin?: string;
429
+ };
425
430
  type PixiVNJsonConditionalOperation = PixiVNJsonOperation | PixiVNJsonIfElse<PixiVNJsonOperation> | PixiVNJsonOperationString;
426
431
 
427
432
  type PixiVNJsonChoice = {
@@ -466,7 +471,7 @@ type PixiVNJsonDialog<Text = string> = {
466
471
  */
467
472
  text: Text;
468
473
  } | Text;
469
- type PixiVNJsonLabelToOpen<T extends {} = {}> = {
474
+ type PixiVNJsonLabelToOpen<T extends {} = object> = {
470
475
  /**
471
476
  * The id of the label to open.
472
477
  */
@@ -483,7 +488,7 @@ type PixiVNJsonLabelToOpen<T extends {} = {}> = {
483
488
  * **It is not recommended to use it, use it only if necessary**. The parameters to be passed to the label. If you want to pass an object, use the {@link PixiVNJsonLabelToOpen.props} attribute.
484
489
  * "params" attribute will be stored in the temp storage with the key: {@link PIXIVNJSON_PARAM_ID} + ({@link narration.openedLabels.length} - 1).
485
490
  */
486
- params?: any[];
491
+ params?: unknown[];
487
492
  };
488
493
  /**
489
494
  * Steps of a label.
@@ -413,7 +413,7 @@ type PixiVNJsonSoundEdit = {
413
413
  type: "sound";
414
414
  operationType: "edit";
415
415
  alias: string;
416
- props: Partial<Pick<MediaInterface, "speed" | "volume" | "muted" | "loop" | "paused">>;
416
+ props: Partial<Pick<MediaInterface, "speed" | "muted" | "loop" | "paused"> & Pick<SoundPlayOptionsWithChannel, "volume">>;
417
417
  };
418
418
  type PixiVNJsonSound = PixiVNJsonSoundPlay | PixiVNJsonSoundRemove | PixiVNJsonSoundPauseResume | PixiVNJsonSoundEdit;
419
419
 
@@ -421,7 +421,12 @@ type PixiVNJsonOperationString = {
421
421
  type: "operationtoconvert";
422
422
  values: (string | PixiVNJsonValueGet | PixiVNJsonConditionalStatements<string | PixiVNJsonValueGet>)[];
423
423
  };
424
- type PixiVNJsonOperation = PixiVNJsonValueSet | PixiVNJsonCanvas | PixiVNJsonSound | PixiVNJsonNarration;
424
+ type PixiVNJsonOperation = (PixiVNJsonValueSet | PixiVNJsonCanvas | PixiVNJsonSound | PixiVNJsonNarration) & {
425
+ /**
426
+ * This value is used by the system to know where this operation is from, for example, if is generated from a string operation.
427
+ */
428
+ $origin?: string;
429
+ };
425
430
  type PixiVNJsonConditionalOperation = PixiVNJsonOperation | PixiVNJsonIfElse<PixiVNJsonOperation> | PixiVNJsonOperationString;
426
431
 
427
432
  type PixiVNJsonChoice = {
@@ -466,7 +471,7 @@ type PixiVNJsonDialog<Text = string> = {
466
471
  */
467
472
  text: Text;
468
473
  } | Text;
469
- type PixiVNJsonLabelToOpen<T extends {} = {}> = {
474
+ type PixiVNJsonLabelToOpen<T extends {} = object> = {
470
475
  /**
471
476
  * The id of the label to open.
472
477
  */
@@ -483,7 +488,7 @@ type PixiVNJsonLabelToOpen<T extends {} = {}> = {
483
488
  * **It is not recommended to use it, use it only if necessary**. The parameters to be passed to the label. If you want to pass an object, use the {@link PixiVNJsonLabelToOpen.props} attribute.
484
489
  * "params" attribute will be stored in the temp storage with the key: {@link PIXIVNJSON_PARAM_ID} + ({@link narration.openedLabels.length} - 1).
485
490
  */
486
- params?: any[];
491
+ params?: unknown[];
487
492
  };
488
493
  /**
489
494
  * Steps of a label.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drincs/pixi-vn-json",
3
- "version": "1.12.0",
3
+ "version": "1.12.1",
4
4
  "type": "module",
5
5
  "description": "Pixi'VN can be integrated with JSON files to create a visual novel.",
6
6
  "main": "./dist/index.cjs",
@@ -79,6 +79,7 @@
79
79
  "typedoc": "^0.28.19",
80
80
  "typedoc-plugin-markdown": "^4.11.0",
81
81
  "typescript": "^5.9.3",
82
+ "typescript-json-schema": "^0.67.1",
82
83
  "vite-tsconfig-paths": "^6.1.1"
83
84
  },
84
85
  "peerDependencies": {