@drincs/pixi-vn
Version:
Pixi'VN is a npm package that provides various features for creating visual novels.
1 lines • 12.4 kB
JavaScript
'use strict';var canvas=require('@drincs/pixi-vn/canvas'),X=require('@drincs/pixi-vn/pixi.js'),motion=require('motion'),core=require('@drincs/pixi-vn/core');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var X__default=/*#__PURE__*/_interopDefault(X);var tt=Object.create;var E=Object.defineProperty;var et=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var it=Object.getPrototypeOf,rt=Object.prototype.hasOwnProperty;var at=(a,e,n)=>e in a?E(a,e,{enumerable:true,configurable:true,writable:true,value:n}):a[e]=n;var q=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var U=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports);var st=(a,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of nt(e))!rt.call(a,r)&&r!==n&&E(a,r,{get:()=>e[r],enumerable:!(i=et(e,r))||i.enumerable});return a};var ot=(a,e,n)=>(n=a!=null?tt(it(a)):{},st(E(n,"default",{value:a,enumerable:true}),a));var v=(a,e,n)=>at(a,typeof e!="symbol"?e+"":e,n);var K=U((P,$)=>{(function(a,e){typeof P=="object"?$.exports=P=e():typeof define=="function"&&define.amd?define([],e):a.CryptoJS=e();})(P,function(){var a=a||(function(e,n){var i;if(typeof window<"u"&&window.crypto&&(i=window.crypto),typeof self<"u"&&self.crypto&&(i=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(i=globalThis.crypto),!i&&typeof window<"u"&&window.msCrypto&&(i=window.msCrypto),!i&&typeof global<"u"&&global.crypto&&(i=global.crypto),!i&&typeof q=="function")try{i=q("crypto");}catch{}var r=function(){if(i){if(typeof i.getRandomValues=="function")try{return i.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof i.randomBytes=="function")try{return i.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},o=Object.create||(function(){function t(){}return function(s){var f;return t.prototype=s,f=new t,t.prototype=null,f}})(),c={},d=c.lib={},u=d.Base=(function(){return {extend:function(t){var s=o(this);return t&&s.mixIn(t),(!s.hasOwnProperty("init")||this.init===s.init)&&(s.init=function(){s.$super.init.apply(this,arguments);}),s.init.prototype=s,s.$super=this,s},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var s in t)t.hasOwnProperty(s)&&(this[s]=t[s]);t.hasOwnProperty("toString")&&(this.toString=t.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),p=d.WordArray=u.extend({init:function(t,s){t=this.words=t||[],s!=n?this.sigBytes=s:this.sigBytes=t.length*4;},toString:function(t){return (t||h).stringify(this)},concat:function(t){var s=this.words,f=t.words,m=this.sigBytes,g=t.sigBytes;if(this.clamp(),m%4)for(var T=0;T<g;T++){var W=f[T>>>2]>>>24-T%4*8&255;s[m+T>>>2]|=W<<24-(m+T)%4*8;}else for(var S=0;S<g;S+=4)s[m+S>>>2]=f[S>>>2];return this.sigBytes+=g,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4);},clone:function(){var t=u.clone.call(this);return t.words=this.words.slice(0),t},random:function(t){for(var s=[],f=0;f<t;f+=4)s.push(r());return new p.init(s,t)}}),l=c.enc={},h=l.Hex={stringify:function(t){for(var s=t.words,f=t.sigBytes,m=[],g=0;g<f;g++){var T=s[g>>>2]>>>24-g%4*8&255;m.push((T>>>4).toString(16)),m.push((T&15).toString(16));}return m.join("")},parse:function(t){for(var s=t.length,f=[],m=0;m<s;m+=2)f[m>>>3]|=parseInt(t.substr(m,2),16)<<24-m%8*4;return new p.init(f,s/2)}},b=l.Latin1={stringify:function(t){for(var s=t.words,f=t.sigBytes,m=[],g=0;g<f;g++){var T=s[g>>>2]>>>24-g%4*8&255;m.push(String.fromCharCode(T));}return m.join("")},parse:function(t){for(var s=t.length,f=[],m=0;m<s;m++)f[m>>>2]|=(t.charCodeAt(m)&255)<<24-m%4*8;return new p.init(f,s)}},A=l.Utf8={stringify:function(t){try{return decodeURIComponent(escape(b.stringify(t)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(t){return b.parse(unescape(encodeURIComponent(t)))}},x=d.BufferedBlockAlgorithm=u.extend({reset:function(){this._data=new p.init,this._nDataBytes=0;},_append:function(t){typeof t=="string"&&(t=A.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes;},_process:function(t){var s,f=this._data,m=f.words,g=f.sigBytes,T=this.blockSize,W=T*4,S=g/W;t?S=e.ceil(S):S=e.max((S|0)-this._minBufferSize,0);var I=S*T,Y=e.min(I*4,g);if(I){for(var R=0;R<I;R+=T)this._doProcessBlock(m,R);s=m.splice(0,I),f.sigBytes-=Y;}return new p.init(s,Y)},clone:function(){var t=u.clone.call(this);return t._data=this._data.clone(),t},_minBufferSize:0});d.Hasher=x.extend({cfg:u.extend(),init:function(t){this.cfg=this.cfg.extend(t),this.reset();},reset:function(){x.reset.call(this),this._doReset();},update:function(t){return this._append(t),this._process(),this},finalize:function(t){t&&this._append(t);var s=this._doFinalize();return s},blockSize:512/32,_createHelper:function(t){return function(s,f){return new t.init(f).finalize(s)}},_createHmacHelper:function(t){return function(s,f){return new y.HMAC.init(t,f).finalize(s)}}});var y=c.algo={};return c})(Math);return a});});var J=U((j,L)=>{(function(a,e){typeof j=="object"?L.exports=j=e(K()):typeof define=="function"&&define.amd?define(["./core"],e):e(a.CryptoJS);})(j,function(a){return (function(){var e=a,n=e.lib,i=n.WordArray,r=n.Hasher,o=e.algo,c=[],d=o.SHA1=r.extend({_doReset:function(){this._hash=new i.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(u,p){for(var l=this._hash.words,h=l[0],b=l[1],A=l[2],x=l[3],B=l[4],y=0;y<80;y++){if(y<16)c[y]=u[p+y]|0;else {var t=c[y-3]^c[y-8]^c[y-14]^c[y-16];c[y]=t<<1|t>>>31;}var s=(h<<5|h>>>27)+B+c[y];y<20?s+=(b&A|~b&x)+1518500249:y<40?s+=(b^A^x)+1859775393:y<60?s+=(b&A|b&x|A&x)-1894007588:s+=(b^A^x)-899497514,B=x,x=A,A=b<<30|b>>>2,b=h,h=s;}l[0]=l[0]+h|0,l[1]=l[1]+b|0,l[2]=l[2]+A|0,l[3]=l[3]+x|0,l[4]=l[4]+B|0;},_doFinalize:function(){var u=this._data,p=u.words,l=this._nDataBytes*8,h=u.sigBytes*8;return p[h>>>5]|=128<<24-h%32,p[(h+64>>>9<<4)+14]=Math.floor(l/4294967296),p[(h+64>>>9<<4)+15]=l,u.sigBytes=p.length*4,this._process(),this._hash},clone:function(){var u=r.clone.call(this);return u._hash=this._hash.clone(),u}});e.SHA1=r._createHelper(d),e.HmacSHA1=r._createHmacHelper(d);})(),a.SHA1});});var H=(a,e=100)=>{let n=null;return (...i)=>{n&&clearTimeout(n),n=setTimeout(()=>a(...i),e);}};var M=a=>e=>{let n=({lastTime:i})=>e(i);return {start:(i=true)=>{a.add(n),a.start();},stop:()=>a.remove(n),now:()=>a.lastTime}};function C(a,e,n){if(Array.isArray(a)&&Array.isArray(a[0])){e&&"repeat"in e&&e?.repeat===null&&(e.repeat=1/0),a.forEach(c=>{if(Array.isArray(c)&&c.length===3){let[d,u,p]=c;p&&"repeat"in p&&p?.repeat===null&&(p.repeat=1/0);}});let{ticker:i=new X__default.default.Ticker,driver:r=M(i),...o}=e||{};return motion.animate(a,{driver:r,...o})}else {n&&"repeat"in n&&n?.repeat===null&&(n.repeat=1/0);let{ticker:i=new X__default.default.Ticker,driver:r=M(i),...o}=n||{};return motion.animate(a,e,{driver:r,...o})}}function ct(a,e){let n={x:0},i=[];return a.forEach((r,o)=>{let{onComplete:c,onPlay:d,...u}=r;if(d){let p=motion.motionValue(o);p.on("change",H(d,50)),i.push([p,o+1,{duration:.01}]);}if(i.push([n,{x:o+1},u]),c){let p=motion.motionValue(o);p.on("change",H(c,50)),i.push([p,o+1,{duration:.01}]);}}),C(i,e)}var G=ot(J());var _=class{constructor(e,n){v(this,"id");v(this,"_args");v(this,"duration");v(this,"priority");v(this,"ticker",new X__default.default.Ticker);v(this,"_animation");v(this,"stopped",false);v(this,"_paused",false);v(this,"canvasElementAliases",[]);v(this,"timeout",50);v(this,"onComplete",()=>{let e=this.id,n=this._args.options?.aliasToRemoveAfter||[];typeof n=="string"&&(n=[n]);let i=this._args.options?.tickerAliasToResume||[];typeof i=="string"&&(i=[i]);let r=this._args.options?.tickerIdToResume||[];typeof r=="string"&&(r=[r]),canvas.canvas.onTickerComplete(e,{aliasToRemoveAfter:n,tickerAliasToResume:i,tickerIdToResume:r,stopTicker:false});});let{duration:i,priority:r,id:o=this.generateTickerId(n),canvasElementAliases:c=[]}=n||{};this._args=e,this.duration=i,this.priority=r,this.id=o,this.canvasElementAliases=c;}get args(){return {...this._args,time:this._animation?.time}}getItemByAlias(e){if(!this.canvasElementAliases.includes(e))return;let n=canvas.canvas.find(e);if(n)return n}generateTickerId(...e){try{return (0,G.default)(JSON.stringify(e)).toString()+"_motion_"+Math.random().toString(36).substring(7)}catch(n){throw new core.PixiError("not_json_serializable",`Error to generate ticker id: ${n}`)}}async complete(){this.animation.complete(),await new Promise(e=>setTimeout(e,this.timeout));}stop(){this.stopped=true,this.animation.stop();}start(){this.args.options?.autoplay!==false&&(this._paused=false,this.animation.play());}createItem(e){return new Proxy({alias:e},{set:({alias:n},i,r)=>{if(this.stopped||this._paused||this._args.startState&&this._args.startState[i]===r)return true;let o=this.getItemByAlias(n);if(!o)return true;switch(i){case "pivotX":o.pivot.x=r;break;case "pivotY":o.pivot.y=r;break;case "scaleX":o.scale.x=r;break;case "scaleY":o.scale.y=r;break;default:o[i]=r;break}return true},get:({alias:n},i)=>{if(this._args.startState||(this._args.startState={}),i in this._args.startState)return this._args.startState[i];let r=this.getItemByAlias(n);if(!r)return;let o;switch(i){case "pivotX":o=r.pivot.x;break;case "pivotY":o=r.pivot.y;break;case "scaleX":o=r.scale.x;break;case "scaleY":o=r.scale.y;break;default:o=r[i];break}return this._args.startState={...this._args.startState,[i]:o},o},has:({alias:n},i)=>{let r=this.getItemByAlias(n);if(!r)return false;switch(i){case "pivotX":return "pivot"in r&&"x"in r.pivot;case "pivotY":return "pivot"in r&&"y"in r.pivot;case "scaleX":return "scale"in r&&"x"in r.scale;case "scaleY":return "scale"in r&&"y"in r.scale;default:return i in r}},ownKeys:({alias:n})=>{let i=this.getItemByAlias(n);return i?Object.keys(i):[]}})}pause(){this.animation&&(this._paused=true,this.animation.pause());}play(){this._paused=false,this.animation.play();}get paused(){return this.animation?this.animation.state==="paused":true}};var O=class extends _{constructor(){super(...arguments);v(this,"alias","motion-sequence");}get animation(){let n=this._animation;if(n)return n;let i=this.canvasElementAliases[0],r=this.createItem(i),o=this._args.sequence.map((c,d)=>[r,c[0],{...c[1]||{},ticker:this.ticker,onComplete:d===this._args.sequence.length-1?()=>this.onComplete():void 0}]);return n=C(o,this._args.options),this._args.time&&(this.animation.time=this._args.time),this._animation=n,n}};var k=class extends _{constructor(){super(...arguments);v(this,"alias","motion");}get animation(){let n=this._animation;if(n)return n;let i=this.canvasElementAliases.map(r=>this.createItem(r));return n=C(i,this._args.keyframes,{...this._args.options,onComplete:()=>this.onComplete(),ticker:this.ticker}),this._args.time&&(n.time=this._args.time),this._animation=n,n}};var w;(r=>(r.log=(o,...c)=>console.log(`[Pixi\u2019VN] ${o}`,...c),r.warn=(o,...c)=>console.warn(`[Pixi\u2019VN] ${o}`,...c),r.error=(o,...c)=>console.error(`[Pixi\u2019VN] ${o}`,...c),r.info=(o,...c)=>console.info(`[Pixi\u2019VN] ${o}`,...c)))(w||(w={}));function z(a){try{if(typeof a>"u")return a;let e=JSON.stringify(a);return JSON.parse(e)}catch(e){throw w.error("Error creating exportable element",a,e),new core.PixiError("not_json_serializable","Error creating exportable element")}}var D;(e=>{function a(n,i,r,o){try{i=z(i);}catch(h){throw w.error("animate keyframes cannot contain functions or classes"),h}try{r=z(r);}catch(h){throw w.error("animate options cannot contain functions or classes"),h}let c=[];typeof n=="string"?c=[n]:Array.isArray(n)?c=n.map(h=>typeof h=="string"?h:h.label):c=[n.label];let d;Array.isArray(i)?d=new O({sequence:i,options:r},{priority:o,canvasElementAliases:c}):d=new k({keyframes:i,options:r},{priority:o,canvasElementAliases:c});let u=canvas.canvas.addTicker(c,d),{forceCompleteBeforeNext:p}=r||{},{completeOnContinue:l=p}=r||{};return u&&l&&canvas.canvas.completeTickerOnStepEnd({id:u}),u}e.animate=a;})(D||(D={}));var lt=D;canvas.RegisteredTickers.add(k,"motion");canvas.RegisteredTickers.add(O,"motion-sequence");exports.animate=C;exports.motion=lt;exports.motionDriver=M;exports.timeline=ct;