You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

simai.js

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simai.js - npm Package Compare versions

Comparing version

to
1.0.11

14

dist/index.d.ts

@@ -0,1 +1,10 @@

declare class TimingChange {
time: number;
tempo: number;
subdivisions: number;
get secondsPerBar(): number;
get secondsPerBeat(): number;
setSeconds(value: number): void;
}
declare enum EachStyle {

@@ -70,2 +79,3 @@ Default = 0,

constructor(vertices: Location[] | undefined);
write(startLocation: Location): string;
}

@@ -92,2 +102,3 @@

constructor(segments: SlideSegment[]);
write(): string;
}

@@ -108,2 +119,3 @@

getVisibleDuration(): number;
write(): string;
}

@@ -121,2 +133,3 @@

noteCollections: NoteCollection[];
timingChanges: TimingChange[];
}

@@ -126,2 +139,3 @@

static deserialize(data: string): MaiChart;
static serialize(chart: MaiChart): string;
}

@@ -128,0 +142,0 @@

14

dist/index.js

@@ -1,8 +0,8 @@

"use strict";var U=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var Y=(a,e)=>{for(var r in e)U(a,r,{get:e[r],enumerable:!0})},ee=(a,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Q(e))!X.call(a,n)&&n!==r&&U(a,n,{get:()=>e[n],enumerable:!(i=G(e,n))||i.enumerable});return a};var re=a=>ee(U({},"__esModule",{value:!0}),a);var te={};Y(te,{EachStyle:()=>N,Location:()=>d,MaiChart:()=>S,Note:()=>w,NoteAppearance:()=>E,NoteCollection:()=>b,NoteGroup:()=>_,NoteStyles:()=>T,NoteType:()=>x,SimaiConvert:()=>V,SimaiFile:()=>z,SlideMorph:()=>y,SlidePath:()=>F,SlideSegment:()=>D,SlideType:()=>C});module.exports=re(te);var h=class extends Error{constructor(r,i,n){super(n);this.name="SimaiException",this.character=i,this.line=r}};var p=class extends h{constructor(r,i,n,o){super(r,i,o);this.name="ScopeMismatchException",this.correctScope=n}};var m=class extends h{constructor(e,r,i){super(e,r,i),this.name="UnsupportedSyntaxException"}};var N=(i=>(i[i.Default=0]="Default",i[i.ForceBroken=1]="ForceBroken",i[i.ForceEach=2]="ForceEach",i))(N||{});var b=class extends Array{constructor(r){super();this.eachStyle=0;this.time=r}addNote(r){r.parentCollection=this,this.push(r)}};var u=class extends h{constructor(r,i,n,o){super(r,i,o);this.name="UnexpectedCharacterException",this.expected=n}};var L=class{static process(e,r){if(r.lexeme[0]==="#"){let n=parseFloat(r.lexeme.slice(1));if(isNaN(n))throw new u(r.line,r.character+1,'0~9, or "."');e.currentTiming.explicitOverride(n);return}let i=parseFloat(r.lexeme);if(isNaN(i))throw new u(r.line,r.character,'0~9, or "."');e.currentTiming.subdivisions=i}};var _=(t=>(t[t.Tap=0]="Tap",t[t.ASensor=1]="ASensor",t[t.BSensor=2]="BSensor",t[t.CSensor=3]="CSensor",t[t.DSensor=4]="DSensor",t[t.ESensor=5]="ESensor",t))(_||{});var C=(s=>(s[s.StraightLine=0]="StraightLine",s[s.RingCw=1]="RingCw",s[s.RingCcw=2]="RingCcw",s[s.Fold=3]="Fold",s[s.CurveCw=4]="CurveCw",s[s.CurveCcw=5]="CurveCcw",s[s.ZigZagS=6]="ZigZagS",s[s.ZigZagZ=7]="ZigZagZ",s[s.EdgeFold=8]="EdgeFold",s[s.EdgeCurveCw=9]="EdgeCurveCw",s[s.EdgeCurveCcw=10]="EdgeCurveCcw",s[s.Fan=11]="Fan",s))(C||{});var d=class{constructor(e,r){this.index=e,this.group=r}equals(e){return this.index===e.index&&this.group===e.group}toString(){return`index: ${this.index}, group: ${this.group.toString()}`}};var S=class{constructor(){this.noteCollections=[]}};var k=class{static process(e,r){let i=parseFloat(r.lexeme);if(isNaN(i))throw new u(r.line,r.character,'0~9, or "."');e.currentTiming.tempo=i}};var I=class extends h{constructor(e,r,i){super(e,r,i),this.name="InvalidSyntaxException"}};var E=(n=>(n[n.Default=0]="Default",n[n.ForceNormal=1]="ForceNormal",n[n.ForceStar=2]="ForceStar",n[n.ForceStarSpinning=3]="ForceStarSpinning",n))(E||{});var T=(t=>(t[t.None=0]="None",t[t.Ex=1]="Ex",t[t.Star=2]="Star",t[t.StarPower=4]="StarPower",t[t.Fireworks=5]="Fireworks",t[t.Mine=6]="Mine",t))(T||{});var y=(r=>(r[r.FadeIn=0]="FadeIn",r[r.SuddenIn=1]="SuddenIn",r))(y||{});var x=(t=>(t[t.Tap=0]="Tap",t[t.Touch=1]="Touch",t[t.Hold=2]="Hold",t[t.Slide=3]="Slide",t[t.Break=4]="Break",t[t.ForceInvalidate=5]="ForceInvalidate",t))(x||{});var w=class{constructor(e){this.location=new d(0,0);this.styles=0;this.appearance=0;this.type=0;this.slideMorph=0;this.slidePaths=[];this.parentCollection=e}get isEx(){return(this.styles&1)!=0}get isStar(){return this.appearance>=2||this.slidePaths.length>0&&this.appearance!==1}getVisibleDuration(){var r;var e=(r=this.length)!=null?r:0;return this.slidePaths.length>0&&(e=Math.max(...this.slidePaths.map(i=>i.delay+i.duration))),e}};var v=class{get secondsPerBar(){return this.tempo===0?0:60/this.tempo}get secondsPerBeat(){return this.secondsPerBar/((this.subdivisions===0?4:this.subdivisions)/4)}constructor(e,r=4){this.tempo=e,this.subdivisions=r}explicitOverride(e){this.tempo=60/e,this.subdivisions=4}};var D=class{constructor(e){this.vertices=e!=null?e:[],this.slideType=0}};var F=class{constructor(e){this.startLocation=new d(0,0);this.delay=0;this.duration=0;this.type=3;this.segments=e}};var O=class a{static process(e,r,i,n){let o=new F([]);o.delay=n.secondsPerBeat,a.readSegment(e,i,r.location,o);let t=!0;for(;!e.endOfFile&&(t||e.moveNext());){var c=e.enumerator.current;switch(t=!1,c.type){case 1:case 2:throw new p(c.line,c.character,4);case 4:{a.decorateSlide(c,o);break}case 5:{let l=o.segments[o.segments.length-1];a.readSegment(e,c,l.vertices[l.vertices.length-1],o),t=!0;break}case 6:{a.readDuration(c,e.currentTiming,o);break}case 7:return e.moveNext(),o;case 8:case 9:case 10:case 3:return o;case 0:break;default:throw new m(c.line,c.character)}}return o}static readSegment(e,r,i,n){let o=new D([]),t=r.lexeme.length;a.assignVertices(e,r,o),o.slideType=a.identifySlideType(r,i,o,t),n.segments.push(o)}static decorateSlide(e,r){switch(e.lexeme[0]){case"b":r.type=4;return;default:throw new m(e.line,e.character)}}static identifySlideType(e,r,i,n){switch(e.lexeme[0]){case"-":return 0;case">":return f.determineRingType(r,i.vertices[0],1);case"<":return f.determineRingType(r,i.vertices[0],-1);case"^":return f.determineRingType(r,i.vertices[0]);case"q":return n===2&&e.lexeme[1]==="q"?9:4;case"p":return n===2&&e.lexeme[1]==="p"?10:5;case"v":return 3;case"V":return 8;case"s":return 6;case"z":return 7;case"w":return 11;default:throw new m(e.line,e.character)}}static assignVertices(e,r,i){do{if(!e.moveNext())throw new m(r.line,r.character);let n=e.enumerator.current,[o,t]=f.tryReadLocation(n);o&&i.vertices.push(t)}while(e.enumerator.current.type===3)}static readDuration(e,r,i){let o=r,t=e.lexeme.indexOf("#");if(t>-1){let K=e.lexeme.lastIndexOf("#")+1-1,W=e.lexeme.substring(0,t),j=t!==K,q=parseFloat(W);if(isNaN(q))throw new u(e.line,e.character,'0~9, or "."');j?i.delay=q:(o.tempo=q,i.delay=o.secondsPerBar)}let l=e.lexeme.substring(0),g=l.indexOf(":");if(g===-1){let s=parseFloat(l);if(isNaN(s))throw new u(e.line,e.character+0,'0~9, or "."');i.duration+=s;return}let H=parseFloat(l.substring(0,g));if(isNaN(H))throw new u(e.line,e.character+0,'0~9, or "."');let J=parseFloat(l.substring(g+1));if(isNaN(J))throw new m(e.line,e.character+0+g+1,'0~9, or "."');i.duration+=o.secondsPerBar/(H/4)*J}};var P=class a{static process(e,r){let[i,n]=f.tryReadLocation(r);if(!i)throw new I(r.line,r.character);let o=new w(e.currentNoteCollection);o.location=n;let t=new v(e.currentNoteCollection.time);n.group!==0&&(o.type=1);let c=!1;for(;!e.endOfFile&&(c||e.moveNext());){let l=e.enumerator.current;switch(c=!1,l.type){case 1:case 2:throw new p(l.line,l.character,4);case 4:{a.decorateNote(l,o);break}case 5:{o.type===2&&(o.length=t.secondsPerBeat);let g=O.process(e,o,l,t);c=!0,o.slidePaths.push(g);break}case 6:{a.readDuration(l,e.currentTiming,o);break}case 7:throw new p(l.line,l.character,2);case 8:case 9:case 10:case 3:return o;case 0:break;default:throw new m(l.line,l.character)}}return o}static decorateNote(e,r){var i;switch(e.lexeme[0]){case"f":r.styles|=5;return;case"b":if(r.type===5)break;r.type=4;return;case"x":r.styles|=1;return;case"m":r.styles|=6;return;case"h":if(r.type===4||r.type===5)break;r.type=2,(i=r.length)!=null||(r.length=0);return;case"?":r.type=5,r.slideMorph=0;return;case"!":r.type=5,r.slideMorph=1;return;case"@":r.appearance=1;return;case"$":r.appearance=r.appearance===2?3:2;return}}static readDuration(e,r,i){if(i.type!==4&&(i.type=2),e.lexeme[0]==="#"){let c=parseFloat(e.lexeme.slice(1));if(isNaN(c))throw new u(e.line,e.character+1,'0~9, or "."');i.length=c;return}let n=e.lexeme.indexOf(":"),o=parseFloat(e.lexeme.slice(0,n)),t=parseFloat(e.lexeme.slice(n+1));if(isNaN(o)||isNaN(t))throw new u(e.line,e.character+1,'0~9, or "."');i.length=r.secondsPerBar/(o/4)*t}};var R=class{constructor(e){this._source=e;this._index=-1;this._done=!1}get current(){return this._current}get index(){return this._index}get done(){return this._done}moveNext(){let e=this._source[Symbol.iterator](),{value:r,done:i}=e.next();return this._current=r,this._done=!!i,this._index++,!i}reset(){this._index=-1,this._done=!1,this._current=void 0}};var f=class{constructor(e){this._chart=new S;this._maxFinishTime=0;this._currentTime=0;this.currentTiming=new v(0,0);this.endOfFile=!1;this.enumerator=new R(e)}getChart(){var i,n,o;let e=[],r=!1;for(;!this.endOfFile&&(r||this.moveNext());){let t=this.enumerator.current;switch(r=!1,t.type){case 1:{k.process(this,t);break}case 2:{L.process(this,t);break}case 3:{if((i=this.currentNoteCollection)!=null||(this.currentNoteCollection=new b(this._currentTime)),t.lexeme[0]==="0"){this.currentNoteCollection.eachStyle!==1&&(this.currentNoteCollection.eachStyle=2);break}let c=P.process(this,t);this.currentNoteCollection.addNote(c),r=!0,this._maxFinishTime=Math.max(this._maxFinishTime,this.currentNoteCollection.time+c.getVisibleDuration());break}case 8:this.currentNoteCollection!=null&&(e.push(this.currentNoteCollection),this.currentNoteCollection=void 0),this._currentTime+=this.currentTiming.secondsPerBeat;break;case 9:switch(t.lexeme[0]){case"/":break;case"`":this.currentNoteCollection!=null&&(this.currentNoteCollection.eachStyle=1);break}break;case 4:throw new p(t.line,t.character,1);case 5:throw new p(t.line,t.character,1);case 6:throw new p(t.line,t.character,3);case 7:throw new p(t.line,t.character,2);case 10:this._chart.finishTiming=this._currentTime;break;case 0:break;default:throw new m(t.line,t.character)}}return(o=(n=this._chart).finishTiming)!=null||(n.finishTiming=this._maxFinishTime),this.currentNoteCollection!==void 0&&(e.push(this.currentNoteCollection),this.currentNoteCollection=void 0),this._chart.noteCollections=e,this._chart}static determineRingType(e,r,i=0){switch(i){case 1:return(e.index+2)%8>=4?2:1;case-1:return(e.index+2)%8>=4?1:2;default:var n=r.index-e.index,o=n>=0?n>4?-1:1:n<-4?1:-1;return o>0?1:2}}static tryReadLocation(e){let r=e.lexeme[0].charCodeAt(0)>="A".charCodeAt(0)&&e.lexeme[0].charCodeAt(0)<="E".charCodeAt(0),i=r?e.lexeme.substring(1):e.lexeme.substring(0),n=0;if(r&&(n=e.lexeme[0].charCodeAt(0)-"A".charCodeAt(0)+1,n===3))return[!0,new d(0,n)];let o=parseInt(i);return o?[!0,new d(o-1,n)]:[!1,new d(0,0)]}moveNext(){return this.endOfFile=!this.enumerator.moveNext(),!this.endOfFile}};var B=class extends h{constructor(e,r,i){super(e,r,i),this.name="UnterminatedSectionException"}};var M=class{constructor(e,r,i,n){this.type=e,this.lexeme=r,this.line=i,this.character=n}};var A=class a{constructor(e){this.space=String.fromCharCode(32);this.enSpace=String.fromCharCode(8194);this.punctuationSpace=String.fromCharCode(8200);this.ideographicSpace=String.fromCharCode(12288);this.lineSeparator=String.fromCharCode(8232);this.paragraphSeparator=String.fromCharCode(8233);this.endOfFileChar="E";this.eachDividerChars=new Set(["/","`"]);this.decoratorChars=new Set(["f","b","x","h","m","!","?","@","$"]);this.slideChars=new Set(["-",">","<","^","p","q","v","V","s","z","w"]);this.separatorChars=new Set(["\r"," ",this.lineSeparator,this.paragraphSeparator,this.space,this.enSpace,this.punctuationSpace,this.ideographicSpace]);this._current=0;this._charIndex=0;this._line=1;this._start=0;this._sequence=e}get isAtEnd(){return this._current>=this._sequence.length}*getTokens(){for(;!this.isAtEnd;){this._start=this._current;let e=this.scanToken();e!==void 0&&(yield e)}}scanToken(){this._charIndex++;let e=this.advance();if(this.decoratorChars.has(e))return this.compileToken(4);if(this.eachDividerChars.has(e))return this.compileToken(9);if(this.separatorChars.has(e))return;switch(e){case",":return this.compileToken(8);case"(":return this.compileSectionToken(1,"(",")");case"{":return this.compileSectionToken(2,"{","}");case"[":return this.compileSectionToken(6,"[","]");case"*":return this.compileToken(7);case`
`:this._line++,this._charIndex=0;return;case this.endOfFileChar:try{let[t,c]=this.tryScanLocationToken();if(t)return this._current+=c-1,this.compileToken(3)}catch(t){}return this.compileToken(10);case"|":{if(this.peek()!=="|")throw new u(this._line,this._charIndex,"|");for(;this.peek()!==`
`&&!this.isAtEnd;)this.advance();return}}let[r,i]=this.tryScanLocationToken();if(r)return this._current+=i-1,this.compileToken(3);let[n,o]=this.isReadingSlideDeclaration();if(n)return this._current+=o-1,this.compileToken(5);throw new m(this._line,this._charIndex)}tryScanLocationToken(){let e=this.peekPrevious();if(a.isButtonLocation(e))return[!0,1];if(!a.isSensorLocation(e))return[!1,0];let r=this.peek();if(a.isButtonLocation(r))return[!0,2];if(e==="C")return[!0,1];let i=this.separatorChars.has(r)||r===`
`||r==="\0";if(e===this.endOfFileChar&&i)return[!1,0];throw new u(this._line,this._charIndex,"1, 2, 3, 4, 5, 6, 7, 8")}isReadingSlideDeclaration(){if(!this.slideChars.has(this.peekPrevious()))return[!1,0];let e=this.peek();return[!0,e==="p"||e==="q"?2:1]}compileSectionToken(e,r,i){for(this._start++;this.peek()!==i;){if(this.isAtEnd||this.peek()===r)throw new B(this._line,this._charIndex);this.advance()}let n=this.compileToken(e);return this.advance(),n}compileToken(e){let r=this._sequence.substring(this._start,this._current);return new M(e,r,this._line,this._charIndex)}static isSensorLocation(e){return e.charCodeAt(0)>="A".charCodeAt(0)&&e.charCodeAt(0)<="E".charCodeAt(0)}static isButtonLocation(e){return e.charCodeAt(0)>="0".charCodeAt(0)&&e.charCodeAt(0)<="8".charCodeAt(0)}advance(){return this._sequence[this._current++]}peek(){return this.isAtEnd?"":this._sequence[this._current]}peekPrevious(){return this._current==0?"":this._sequence[this._current-1]}};var V=class{static deserialize(e){let r=new A(e).getTokens();return new f(r).getChart()}};var z=class{constructor(e){this.data="";this.data=e}toKeyValuePairs(){let e="",r="",i=this.data.replace(/\r\n/g,`
"use strict";var Z=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var ee=(s,e)=>{for(var t in e)Z(s,t,{get:e[t],enumerable:!0})},te=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of X(e))!Y.call(s,n)&&n!==t&&Z(s,n,{get:()=>e[n],enumerable:!(r=Q(e,n))||r.enumerable});return s};var ie=s=>te(Z({},"__esModule",{value:!0}),s);var re={};ee(re,{EachStyle:()=>x,Location:()=>g,MaiChart:()=>T,Note:()=>F,NoteAppearance:()=>E,NoteCollection:()=>w,NoteGroup:()=>v,NoteStyles:()=>D,NoteType:()=>C,SimaiConvert:()=>z,SimaiFile:()=>V,SlideMorph:()=>y,SlidePath:()=>N,SlideSegment:()=>_,SlideType:()=>S});module.exports=ie(re);var u=class extends Error{constructor(t,r,n){super(n);this.name="SimaiException",this.character=r,this.line=t}};var p=class extends u{constructor(t,r,n,o){super(t,r,o);this.name="ScopeMismatchException",this.correctScope=n}};var m=class extends u{constructor(e,t,r){super(e,t,r),this.name="UnsupportedSyntaxException"}};var x=(r=>(r[r.Default=0]="Default",r[r.ForceBroken=1]="ForceBroken",r[r.ForceEach=2]="ForceEach",r))(x||{});var w=class extends Array{constructor(t){super();this.eachStyle=0;this.time=t}addNote(t){t.parentCollection=this,this.push(t)}};var h=class extends u{constructor(t,r,n,o){super(t,r,o);this.name="UnexpectedCharacterException",this.expected=n}};var d=class{constructor(){this.time=0;this.tempo=0;this.subdivisions=0}get secondsPerBar(){return this.tempo===0?0:60/this.tempo}get secondsPerBeat(){return this.secondsPerBar/((this.subdivisions===0?4:this.subdivisions)/4)}setSeconds(e){this.tempo=60/e,this.subdivisions=4}};var k=class{static process(e,t){if(t.lexeme[0]==="#"){let o=parseFloat(t.lexeme.slice(1));if(isNaN(o))throw new h(t.line,t.character+1,'0~9, or "."');let i;{let c=e.timingChanges[e.timingChanges.length-1];i=new d,i.tempo=c.tempo,i.subdivisions=c.subdivisions}i.setSeconds(o),i.time=e.currentTime,Math.abs(e.timingChanges[e.timingChanges.length-1].time-e.currentTime)<=1401298e-51&&e.timingChanges.pop(),e.timingChanges.push(i);return}let r=parseFloat(t.lexeme);if(isNaN(r))throw new h(t.line,t.character,'0~9, or "."');let n;{let o=e.timingChanges[e.timingChanges.length-1];n=new d,n.tempo=o.tempo,n.subdivisions=o.subdivisions}n.subdivisions=r,n.time=e.currentTime,Math.abs(e.timingChanges[e.timingChanges.length-1].time-e.currentTime)<=1401298e-51&&e.timingChanges.pop(),e.timingChanges.push(n)}};var v=(i=>(i[i.Tap=0]="Tap",i[i.ASensor=1]="ASensor",i[i.BSensor=2]="BSensor",i[i.CSensor=3]="CSensor",i[i.DSensor=4]="DSensor",i[i.ESensor=5]="ESensor",i))(v||{});var S=(a=>(a[a.StraightLine=0]="StraightLine",a[a.RingCw=1]="RingCw",a[a.RingCcw=2]="RingCcw",a[a.Fold=3]="Fold",a[a.CurveCw=4]="CurveCw",a[a.CurveCcw=5]="CurveCcw",a[a.ZigZagS=6]="ZigZagS",a[a.ZigZagZ=7]="ZigZagZ",a[a.EdgeFold=8]="EdgeFold",a[a.EdgeCurveCw=9]="EdgeCurveCw",a[a.EdgeCurveCcw=10]="EdgeCurveCcw",a[a.Fan=11]="Fan",a))(S||{});var g=class{constructor(e,t){this.index=e,this.group=t}equals(e){return this.index===e.index&&this.group===e.group}toString(){switch(this.group){case 0:return(this.index+1).toString();case 3:return"C";default:let e="";switch(this.group){case 1:e="A";break;case 2:e="B";break;case 4:e="D";break;case 5:e="E";break}return e+(this.index+1).toString()}}};var T=class{constructor(){this.noteCollections=[];this.timingChanges=[]}};var L=class{static process(e,t){let r=parseFloat(t.lexeme);if(isNaN(r))throw new h(t.line,t.character,'0~9, or "."');let n;{let o=e.timingChanges[e.timingChanges.length-1];n=new d,n.tempo=o.tempo,n.subdivisions=o.subdivisions}n.tempo=r,n.time=e.currentTime,Math.abs(e.timingChanges[e.timingChanges.length-1].time-e.currentTime)<=1401298e-51&&e.timingChanges.pop(),e.timingChanges.push(n)}};var M=class extends u{constructor(e,t,r){super(e,t,r),this.name="InvalidSyntaxException"}};var E=(n=>(n[n.Default=0]="Default",n[n.ForceNormal=1]="ForceNormal",n[n.ForceStar=2]="ForceStar",n[n.ForceStarSpinning=3]="ForceStarSpinning",n))(E||{});var D=(i=>(i[i.None=0]="None",i[i.Ex=1]="Ex",i[i.Star=2]="Star",i[i.StarPower=4]="StarPower",i[i.Fireworks=5]="Fireworks",i[i.Mine=6]="Mine",i))(D||{});var y=(t=>(t[t.FadeIn=0]="FadeIn",t[t.SuddenIn=1]="SuddenIn",t))(y||{});var C=(i=>(i[i.Tap=0]="Tap",i[i.Touch=1]="Touch",i[i.Hold=2]="Hold",i[i.Slide=3]="Slide",i[i.Break=4]="Break",i[i.ForceInvalidate=5]="ForceInvalidate",i))(C||{});var F=class{constructor(e){this.location=new g(0,0);this.styles=0;this.appearance=0;this.type=0;this.slideMorph=0;this.slidePaths=[];this.parentCollection=e}get isEx(){return(this.styles&1)!=0}get isStar(){return this.appearance>=2||this.slidePaths.length>0&&this.appearance!==1}getVisibleDuration(){var t;var e=(t=this.length)!=null?t:0;return this.slidePaths.length>0&&(e=Math.max(...this.slidePaths.map(r=>r.delay+r.duration))),e}write(){let e="";switch(e+=this.location.toString(),this.styles&1&&(e+="x"),this.styles&6&&(e+="m"),this.type===5&&(e+=this.slideMorph===0?"?":"!"),this.appearance){case 1:e+="@";break;case 3:e+="$$";break;case 2:e+="$";break}this.length&&`${this.length.toFixed(7)}`;for(let t=0;t<this.slidePaths.length;t++)t>0&&(e+="*"),e+=this.slidePaths[t].write();return e}};var _=class{constructor(e){this.vertices=e!=null?e:[],this.slideType=0}write(e){let t="";switch(this.slideType){case 0:t+=`-${this.vertices[0]}`;break;case 1:t+=(e.index+2)%8>=4?`<${this.vertices[0]}`:`>${this.vertices[0]}`;break;case 2:t+=(e.index+2)%8>=4?`<${this.vertices[0]}`:`>${this.vertices[0]}`;break;case 3:t+=`v${this.vertices[0]}`;break;case 4:t+=`q${this.vertices[0]}`;break;case 5:t+=`pp${this.vertices[0]}`;break;case 6:t+=`s${this.vertices[0]}`;break;case 7:t+=`z${this.vertices[0]}`;break;case 8:t+=`V${this.vertices[0]}${this.vertices[1]}`;break;case 9:t+=`qq${this.vertices[0]}`;case 10:t+=`pp${this.vertices[0]}`;case 11:t+=`w${this.vertices[0]}`}return t}};var N=class{constructor(e){this.startLocation=new g(0,0);this.delay=0;this.duration=0;this.type=3;this.segments=e}write(){let e="";for(let t of this.segments)e+=t.write(this.startLocation);return this.type===4&&(e+="b"),e+=`[${this.delay.toFixed(7)}##${this.duration.toFixed(7)}]`,e}};var P=class s{static process(e,t,r,n){let o=new N([]);o.delay=n.secondsPerBeat,s.readSegment(e,r,t.location,o);let i=!0;for(;!e.endOfFile&&(i||e.moveNext());){var c=e.enumerator.current;switch(i=!1,c.type){case 1:case 2:throw new p(c.line,c.character,4);case 4:{s.decorateSlide(c,o);break}case 5:{let l=o.segments[o.segments.length-1];s.readSegment(e,c,l.vertices[l.vertices.length-1],o),i=!0;break}case 6:{s.readDuration(e.timingChanges[e.timingChanges.length-1],c,o);break}case 7:return e.moveNext(),o;case 8:case 9:case 10:case 3:return o;case 0:break;default:throw new m(c.line,c.character)}}return o}static readSegment(e,t,r,n){let o=new _([]),i=t.lexeme.length;s.assignVertices(e,t,o),o.slideType=s.identifySlideType(t,r,o,i),n.segments.push(o)}static decorateSlide(e,t){switch(e.lexeme[0]){case"b":t.type=4;return;default:throw new m(e.line,e.character)}}static identifySlideType(e,t,r,n){switch(e.lexeme[0]){case"-":return 0;case">":return f.determineRingType(t,r.vertices[0],1);case"<":return f.determineRingType(t,r.vertices[0],-1);case"^":return f.determineRingType(t,r.vertices[0]);case"q":return n===2&&e.lexeme[1]==="q"?9:4;case"p":return n===2&&e.lexeme[1]==="p"?10:5;case"v":return 3;case"V":return 8;case"s":return 6;case"z":return 7;case"w":return 11;default:throw new m(e.line,e.character)}}static assignVertices(e,t,r){do{if(!e.moveNext())throw new m(t.line,t.character);let n=e.enumerator.current,[o,i]=f.tryReadLocation(n);o&&r.vertices.push(i)}while(e.enumerator.current.type===3)}static readDuration(e,t,r){let o=e,i=t.lexeme.indexOf("#");if(i>-1){let W=t.lexeme.lastIndexOf("#")+1-1,j=t.lexeme.substring(0,i),G=i!==W,q=parseFloat(j);if(isNaN(q))throw new h(t.line,t.character,'0~9, or "."');G?r.delay=q:(o.tempo=q,r.delay=o.secondsPerBar)}let l=t.lexeme.substring(0),b=l.indexOf(":");if(b===-1){let a=parseFloat(l);if(isNaN(a))throw new h(t.line,t.character+0,'0~9, or "."');r.duration+=a;return}let H=parseFloat(l.substring(0,b));if(isNaN(H))throw new h(t.line,t.character+0,'0~9, or "."');let J=parseFloat(l.substring(b+1));if(isNaN(J))throw new m(t.line,t.character+0+b+1,'0~9, or "."');r.duration+=o.secondsPerBar/(H/4)*J}};var I=class s{static process(e,t){let[r,n]=f.tryReadLocation(t);if(!r)throw new M(t.line,t.character);let o=new F(e.currentNoteCollection);o.location=n;let i=new d;i.tempo=e.timingChanges[e.timingChanges.length-1].tempo,n.group!==0&&(o.type=1);let c=!1;for(;!e.endOfFile&&(c||e.moveNext());){let l=e.enumerator.current;switch(c=!1,l.type){case 1:case 2:throw new p(l.line,l.character,4);case 4:{s.decorateNote(l,o);break}case 5:{o.type===2&&(o.length=i.secondsPerBeat);let b=P.process(e,o,l,i);c=!0,o.slidePaths.push(b);break}case 6:{s.readDuration(e.timingChanges[e.timingChanges.length-1],l,o);break}case 7:throw new p(l.line,l.character,2);case 8:case 9:case 10:case 3:return o;case 0:break;default:throw new m(l.line,l.character)}}return o}static decorateNote(e,t){var r;switch(e.lexeme[0]){case"f":t.styles|=5;return;case"b":if(t.type===5)break;t.type=4;return;case"x":t.styles|=1;return;case"m":t.styles|=6;return;case"h":t.type!==4&&t.type!==5&&(t.type=2),(r=t.length)!=null||(t.length=0);return;case"?":t.type=5,t.slideMorph=0;return;case"!":t.type=5,t.slideMorph=1;return;case"@":t.appearance=1;return;case"$":t.appearance=t.appearance===2?3:2;return}}static readDuration(e,t,r){if(r.type!==4&&(r.type=2),t.lexeme[0]==="#"){let c=parseFloat(t.lexeme.slice(1));if(isNaN(c))throw new h(t.line,t.character+1,'0~9, or "."');r.length=c;return}let n=t.lexeme.indexOf(":"),o=parseFloat(t.lexeme.slice(0,n)),i=parseFloat(t.lexeme.slice(n+1));if(isNaN(o)||isNaN(i))throw new h(t.line,t.character+1,'0~9, or "."');r.length=e.secondsPerBar/(o/4)*i}};var O=class{constructor(e){this._source=e;this._index=-1;this._done=!1}get current(){return this._current}get index(){return this._index}get done(){return this._done}moveNext(){let e=this._source[Symbol.iterator](),{value:t,done:r}=e.next();return this._current=t,this._done=!!r,this._index++,!r}reset(){this._index=-1,this._done=!1,this._current=void 0}};var f=class{constructor(e){this._chart=new T;this.timingChanges=[];this._maxFinishTime=0;this.enumerator=new O(e),this.timingChanges.push(new d),this.currentNoteCollection=void 0,this.currentTime=0,this.endOfFile=!1}getChart(){var r,n,o;let e=[],t=!1;for(;!this.endOfFile&&(t||this.moveNext());){let i=this.enumerator.current;switch(t=!1,i.type){case 1:{L.process(this,i);break}case 2:{k.process(this,i);break}case 3:{if((r=this.currentNoteCollection)!=null||(this.currentNoteCollection=new w(this.currentTime)),i.lexeme[0]==="0"){this.currentNoteCollection.eachStyle!==1&&(this.currentNoteCollection.eachStyle=2);break}let c=I.process(this,i);this.currentNoteCollection.addNote(c),t=!0,this._maxFinishTime=Math.max(this._maxFinishTime,this.currentNoteCollection.time+c.getVisibleDuration());break}case 8:this.currentNoteCollection!=null&&(e.push(this.currentNoteCollection),this.currentNoteCollection=void 0),this.currentTime+=this.timingChanges[this.timingChanges.length-1].secondsPerBeat;break;case 9:switch(i.lexeme[0]){case"/":break;case"`":this.currentNoteCollection!=null&&(this.currentNoteCollection.eachStyle=1);break}break;case 4:throw new p(i.line,i.character,1);case 5:throw new p(i.line,i.character,1);case 6:throw new p(i.line,i.character,3);case 7:throw new p(i.line,i.character,2);case 10:this._chart.finishTiming=this.currentTime;break;case 0:break;default:throw new m(i.line,i.character)}}return(o=(n=this._chart).finishTiming)!=null||(n.finishTiming=this._maxFinishTime),this.currentNoteCollection!==void 0&&(e.push(this.currentNoteCollection),this.currentNoteCollection=void 0),this._chart.noteCollections=e,this._chart.timingChanges=this.timingChanges,this._chart}static determineRingType(e,t,r=0){switch(r){case 1:return(e.index+2)%8>=4?2:1;case-1:return(e.index+2)%8>=4?1:2;default:var n=t.index-e.index,o=n>=0?n>4?-1:1:n<-4?1:-1;return o>0?1:2}}static tryReadLocation(e){let t=e.lexeme[0].charCodeAt(0)>="A".charCodeAt(0)&&e.lexeme[0].charCodeAt(0)<="E".charCodeAt(0),r=t?e.lexeme.substring(1):e.lexeme.substring(0),n=0;if(t&&(n=e.lexeme[0].charCodeAt(0)-"A".charCodeAt(0)+1,n===3))return[!0,new g(0,n)];let o=parseInt(r);return o?[!0,new g(o-1,n)]:[!1,new g(0,0)]}moveNext(){return this.endOfFile=!this.enumerator.moveNext(),!this.endOfFile}};var $=class extends u{constructor(e,t,r){super(e,t,r),this.name="UnterminatedSectionException"}};var B=class{constructor(e,t,r,n){this.type=e,this.lexeme=t,this.line=r,this.character=n}};var R=class s{constructor(e){this.space=String.fromCharCode(32);this.enSpace=String.fromCharCode(8194);this.punctuationSpace=String.fromCharCode(8200);this.ideographicSpace=String.fromCharCode(12288);this.lineSeparator=String.fromCharCode(8232);this.paragraphSeparator=String.fromCharCode(8233);this.endOfFileChar="E";this.eachDividerChars=new Set(["/","`"]);this.decoratorChars=new Set(["f","b","x","h","m","!","?","@","$"]);this.slideChars=new Set(["-",">","<","^","p","q","v","V","s","z","w"]);this.separatorChars=new Set(["\r"," ",this.lineSeparator,this.paragraphSeparator,this.space,this.enSpace,this.punctuationSpace,this.ideographicSpace]);this._current=0;this._charIndex=0;this._line=1;this._start=0;this._sequence=e}get isAtEnd(){return this._current>=this._sequence.length}*getTokens(){for(;!this.isAtEnd;){this._start=this._current;let e=this.scanToken();e!==void 0&&(yield e)}}scanToken(){this._charIndex++;let e=this.advance();if(this.decoratorChars.has(e))return this.compileToken(4);if(this.eachDividerChars.has(e))return this.compileToken(9);if(this.separatorChars.has(e))return;switch(e){case",":return this.compileToken(8);case"(":return this.compileSectionToken(1,"(",")");case"{":return this.compileSectionToken(2,"{","}");case"[":return this.compileSectionToken(6,"[","]");case"*":return this.compileToken(7);case`
`:this._line++,this._charIndex=0;return;case this.endOfFileChar:try{let[i,c]=this.tryScanLocationToken();if(i)return this._current+=c-1,this.compileToken(3)}catch(i){}return this.compileToken(10);case"|":{if(this.peek()!=="|")throw new h(this._line,this._charIndex,"|");for(;this.peek()!==`
`&&!this.isAtEnd;)this.advance();return}}let[t,r]=this.tryScanLocationToken();if(t)return this._current+=r-1,this.compileToken(3);let[n,o]=this.isReadingSlideDeclaration();if(n)return this._current+=o-1,this.compileToken(5);throw new m(this._line,this._charIndex)}tryScanLocationToken(){let e=this.peekPrevious();if(s.isButtonLocation(e))return[!0,1];if(!s.isSensorLocation(e))return[!1,0];let t=this.peek();if(s.isButtonLocation(t))return[!0,2];if(e==="C")return[!0,1];let r=this.separatorChars.has(t)||t===`
`||t==="\0";if(e===this.endOfFileChar&&r)return[!1,0];throw new h(this._line,this._charIndex,"1, 2, 3, 4, 5, 6, 7, 8")}isReadingSlideDeclaration(){if(!this.slideChars.has(this.peekPrevious()))return[!1,0];let e=this.peek();return[!0,e==="p"||e==="q"?2:1]}compileSectionToken(e,t,r){for(this._start++;this.peek()!==r;){if(this.isAtEnd||this.peek()===t)throw new $(this._line,this._charIndex);this.advance()}let n=this.compileToken(e);return this.advance(),n}compileToken(e){let t=this._sequence.substring(this._start,this._current);return new B(e,t,this._line,this._charIndex)}static isSensorLocation(e){return e.charCodeAt(0)>="A".charCodeAt(0)&&e.charCodeAt(0)<="E".charCodeAt(0)}static isButtonLocation(e){return e.charCodeAt(0)>="0".charCodeAt(0)&&e.charCodeAt(0)<="8".charCodeAt(0)}advance(){return this._sequence[this._current++]}peek(){return this.isAtEnd?"":this._sequence[this._current]}peekPrevious(){return this._current==0?"":this._sequence[this._current-1]}};var A=class s{constructor(){this._currentTimingChange=0;this._currentNoteCollection=0;this._currentTime=0}serialize(e){let t="";for(t+=`(${e.timingChanges[this._currentTimingChange].tempo})`,t+=`{${e.timingChanges[this._currentTimingChange].subdivisions}}`;this._currentTime<=(e.finishTiming?e.finishTiming:0);){this._currentTimingChange<e.timingChanges.length-1&&Math.abs(e.timingChanges[this._currentTimingChange+1].time-this._currentTime)<1401298e-51&&(this._currentTimingChange++,Math.abs(e.timingChanges[this._currentTimingChange].tempo-e.timingChanges[this._currentTimingChange-1].tempo)>1401298e-51&&(t+=`(${e.timingChanges[this._currentTimingChange].tempo})`),Math.abs(e.timingChanges[this._currentTimingChange].subdivisions-e.timingChanges[this._currentTimingChange-1].subdivisions)>1401298e-51&&(t+=`{${e.timingChanges[this._currentTimingChange].subdivisions}}`)),this._currentNoteCollection<e.noteCollections.length&&Math.abs(e.noteCollections[this._currentNoteCollection].time-this._currentTime)<=1401298e-51&&(t+=s.serializeNoteCollection(e.noteCollections[this._currentNoteCollection]),this._currentNoteCollection++);let r=e.timingChanges[this._currentTimingChange];this._currentTime+=r.secondsPerBeat,t+=","}return t+="E",t}static serializeNoteCollection(e){let t="",r=e.eachStyle===1?"`":"/";e.eachStyle===2&&(t+="0/");for(let n=0;n<e.length;n++)t+=e[n].write(),n!=e.length-1&&(t+=r);return t}};var z=class{static deserialize(e){let t=new R(e).getTokens();return new f(t).getChart()}static serialize(e){return new A().serialize(e)}};var V=class{constructor(e){this.data="";this.data=e}toKeyValuePairs(){let e="",t="",r=this.data.replace(/\r\n/g,`
`).split(`
`),n=new Map;for(let o of i)if(o.startsWith("&")){e!=""&&(n.set(e,r.trim()),r="");let t=o.split("=",2);e=t[0].substring(1),r+=t[1]+`
`}else r+=o+`
`;return e&&n.set(e,r.trim()),n}getValue(e){var r;return(r=this.toKeyValuePairs().get(e))!=null?r:""}};0&&(module.exports={EachStyle,Location,MaiChart,Note,NoteAppearance,NoteCollection,NoteGroup,NoteStyles,NoteType,SimaiConvert,SimaiFile,SlideMorph,SlidePath,SlideSegment,SlideType});
`),n=new Map;for(let o of r)if(o.startsWith("&")){e!=""&&(n.set(e,t.trim()),t="");let i=o.split("=",2);e=i[0].substring(1),t+=i[1]+`
`}else t+=o+`
`;return e&&n.set(e,t.trim()),n}getValue(e){var t;return(t=this.toKeyValuePairs().get(e))!=null?t:""}};0&&(module.exports={EachStyle,Location,MaiChart,Note,NoteAppearance,NoteCollection,NoteGroup,NoteStyles,NoteType,SimaiConvert,SimaiFile,SlideMorph,SlidePath,SlideSegment,SlideType});

@@ -0,0 +0,0 @@ const { SimaiFile, SimaiConvert } = require("simai.js");

{
"name": "simai.js",
"version": "1.0.10",
"version": "1.0.11",
"description": "A serializer(wip)/deserializer for the rhythm game chart format simai.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -0,0 +0,0 @@ ![simai.js Banner](./assets/banner.jpg)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet