Comparing version 1.0.0 to 1.0.1
431
dist/vmd.js
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Vmd = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('shiftjis')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'shiftjis'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Vmd = {}, global.shiftjis)); | ||
}(this, (function (exports, shiftjis) { 'use strict'; | ||
@@ -145,421 +145,2 @@ function _classCallCheck(instance, Constructor) { | ||
var global$1 = typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}; | ||
// based off https://github.com/defunctzombie/node-process/blob/master/browser.js | ||
function defaultSetTimout() { | ||
throw new Error('setTimeout has not been defined'); | ||
} | ||
function defaultClearTimeout() { | ||
throw new Error('clearTimeout has not been defined'); | ||
} | ||
var cachedSetTimeout = defaultSetTimout; | ||
var cachedClearTimeout = defaultClearTimeout; | ||
if (typeof global$1.setTimeout === 'function') { | ||
cachedSetTimeout = setTimeout; | ||
} | ||
if (typeof global$1.clearTimeout === 'function') { | ||
cachedClearTimeout = clearTimeout; | ||
} | ||
function runTimeout(fun) { | ||
if (cachedSetTimeout === setTimeout) { | ||
//normal enviroments in sane situations | ||
return setTimeout(fun, 0); | ||
} // if setTimeout wasn't available but was latter defined | ||
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { | ||
cachedSetTimeout = setTimeout; | ||
return setTimeout(fun, 0); | ||
} | ||
try { | ||
// when when somebody has screwed with setTimeout but no I.E. maddness | ||
return cachedSetTimeout(fun, 0); | ||
} catch (e) { | ||
try { | ||
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally | ||
return cachedSetTimeout.call(null, fun, 0); | ||
} catch (e) { | ||
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error | ||
return cachedSetTimeout.call(this, fun, 0); | ||
} | ||
} | ||
} | ||
function runClearTimeout(marker) { | ||
if (cachedClearTimeout === clearTimeout) { | ||
//normal enviroments in sane situations | ||
return clearTimeout(marker); | ||
} // if clearTimeout wasn't available but was latter defined | ||
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { | ||
cachedClearTimeout = clearTimeout; | ||
return clearTimeout(marker); | ||
} | ||
try { | ||
// when when somebody has screwed with setTimeout but no I.E. maddness | ||
return cachedClearTimeout(marker); | ||
} catch (e) { | ||
try { | ||
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally | ||
return cachedClearTimeout.call(null, marker); | ||
} catch (e) { | ||
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. | ||
// Some versions of I.E. have different rules for clearTimeout vs setTimeout | ||
return cachedClearTimeout.call(this, marker); | ||
} | ||
} | ||
} | ||
var queue = []; | ||
var draining = false; | ||
var currentQueue; | ||
var queueIndex = -1; | ||
function cleanUpNextTick() { | ||
if (!draining || !currentQueue) { | ||
return; | ||
} | ||
draining = false; | ||
if (currentQueue.length) { | ||
queue = currentQueue.concat(queue); | ||
} else { | ||
queueIndex = -1; | ||
} | ||
if (queue.length) { | ||
drainQueue(); | ||
} | ||
} | ||
function drainQueue() { | ||
if (draining) { | ||
return; | ||
} | ||
var timeout = runTimeout(cleanUpNextTick); | ||
draining = true; | ||
var len = queue.length; | ||
while (len) { | ||
currentQueue = queue; | ||
queue = []; | ||
while (++queueIndex < len) { | ||
if (currentQueue) { | ||
currentQueue[queueIndex].run(); | ||
} | ||
} | ||
queueIndex = -1; | ||
len = queue.length; | ||
} | ||
currentQueue = null; | ||
draining = false; | ||
runClearTimeout(timeout); | ||
} | ||
function nextTick(fun) { | ||
var args = new Array(arguments.length - 1); | ||
if (arguments.length > 1) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
args[i - 1] = arguments[i]; | ||
} | ||
} | ||
queue.push(new Item(fun, args)); | ||
if (queue.length === 1 && !draining) { | ||
runTimeout(drainQueue); | ||
} | ||
} // v8 likes predictible objects | ||
function Item(fun, array) { | ||
this.fun = fun; | ||
this.array = array; | ||
} | ||
Item.prototype.run = function () { | ||
this.fun.apply(null, this.array); | ||
}; | ||
var title = 'browser'; | ||
var platform = 'browser'; | ||
var browser = true; | ||
var env = {}; | ||
var argv = []; | ||
var version = ''; // empty string to avoid regexp issues | ||
var versions = {}; | ||
var release = {}; | ||
var config = {}; | ||
function noop() {} | ||
var on = noop; | ||
var addListener = noop; | ||
var once = noop; | ||
var off = noop; | ||
var removeListener = noop; | ||
var removeAllListeners = noop; | ||
var emit = noop; | ||
function binding(name) { | ||
throw new Error('process.binding is not supported'); | ||
} | ||
function cwd() { | ||
return '/'; | ||
} | ||
function chdir(dir) { | ||
throw new Error('process.chdir is not supported'); | ||
} | ||
function umask() { | ||
return 0; | ||
} // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js | ||
var performance = global$1.performance || {}; | ||
var performanceNow = performance.now || performance.mozNow || performance.msNow || performance.oNow || performance.webkitNow || function () { | ||
return new Date().getTime(); | ||
}; // generate timestamp or delta | ||
// see http://nodejs.org/api/process.html#process_process_hrtime | ||
function hrtime(previousTimestamp) { | ||
var clocktime = performanceNow.call(performance) * 1e-3; | ||
var seconds = Math.floor(clocktime); | ||
var nanoseconds = Math.floor(clocktime % 1 * 1e9); | ||
if (previousTimestamp) { | ||
seconds = seconds - previousTimestamp[0]; | ||
nanoseconds = nanoseconds - previousTimestamp[1]; | ||
if (nanoseconds < 0) { | ||
seconds--; | ||
nanoseconds += 1e9; | ||
} | ||
} | ||
return [seconds, nanoseconds]; | ||
} | ||
var startTime = new Date(); | ||
function uptime() { | ||
var currentTime = new Date(); | ||
var dif = currentTime - startTime; | ||
return dif / 1000; | ||
} | ||
var browser$1 = { | ||
nextTick: nextTick, | ||
title: title, | ||
browser: browser, | ||
env: env, | ||
argv: argv, | ||
version: version, | ||
versions: versions, | ||
on: on, | ||
addListener: addListener, | ||
once: once, | ||
off: off, | ||
removeListener: removeListener, | ||
removeAllListeners: removeAllListeners, | ||
emit: emit, | ||
binding: binding, | ||
cwd: cwd, | ||
chdir: chdir, | ||
umask: umask, | ||
hrtime: hrtime, | ||
platform: platform, | ||
release: release, | ||
config: config, | ||
uptime: uptime | ||
}; | ||
// Solution would be installing npm modules "buffer" and "stream" explicitly. | ||
var Buffer = require("safer-buffer").Buffer; | ||
var bomHandling = require("./bom-handling"), | ||
iconv = module.exports; // All codecs and aliases are kept here, keyed by encoding name/alias. | ||
// They are lazy loaded in `iconv.getCodec` from `encodings/index.js`. | ||
iconv.encodings = null; // Characters emitted in case of error. | ||
iconv.defaultCharUnicode = '�'; | ||
iconv.defaultCharSingleByte = '?'; // Public API. | ||
iconv.encode = function encode(str, encoding, options) { | ||
str = "" + (str || ""); // Ensure string. | ||
var encoder = iconv.getEncoder(encoding, options); | ||
var res = encoder.write(str); | ||
var trail = encoder.end(); | ||
return trail && trail.length > 0 ? Buffer.concat([res, trail]) : res; | ||
}; | ||
iconv.decode = function decode(buf, encoding, options) { | ||
if (typeof buf === 'string') { | ||
if (!iconv.skipDecodeWarning) { | ||
console.error('Iconv-lite warning: decode()-ing strings is deprecated. Refer to https://github.com/ashtuchkin/iconv-lite/wiki/Use-Buffers-when-decoding'); | ||
iconv.skipDecodeWarning = true; | ||
} | ||
buf = Buffer.from("" + (buf || ""), "binary"); // Ensure buffer. | ||
} | ||
var decoder = iconv.getDecoder(encoding, options); | ||
var res = decoder.write(buf); | ||
var trail = decoder.end(); | ||
return trail ? res + trail : res; | ||
}; | ||
iconv.encodingExists = function encodingExists(enc) { | ||
try { | ||
iconv.getCodec(enc); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
}; // Legacy aliases to convert functions | ||
iconv.toEncoding = iconv.encode; | ||
iconv.fromEncoding = iconv.decode; // Search for a codec in iconv.encodings. Cache codec data in iconv._codecDataCache. | ||
iconv._codecDataCache = {}; | ||
iconv.getCodec = function getCodec(encoding) { | ||
if (!iconv.encodings) iconv.encodings = require("../encodings"); // Lazy load all encoding definitions. | ||
// Canonicalize encoding name: strip all non-alphanumeric chars and appended year. | ||
var enc = iconv._canonicalizeEncoding(encoding); // Traverse iconv.encodings to find actual codec. | ||
var codecOptions = {}; | ||
while (true) { | ||
var codec = iconv._codecDataCache[enc]; | ||
if (codec) return codec; | ||
var codecDef = iconv.encodings[enc]; | ||
switch (typeof codecDef) { | ||
case "string": | ||
// Direct alias to other encoding. | ||
enc = codecDef; | ||
break; | ||
case "object": | ||
// Alias with options. Can be layered. | ||
for (var key in codecDef) codecOptions[key] = codecDef[key]; | ||
if (!codecOptions.encodingName) codecOptions.encodingName = enc; | ||
enc = codecDef.type; | ||
break; | ||
case "function": | ||
// Codec itself. | ||
if (!codecOptions.encodingName) codecOptions.encodingName = enc; // The codec function must load all tables and return object with .encoder and .decoder methods. | ||
// It'll be called only once (for each different options object). | ||
codec = new codecDef(codecOptions, iconv); | ||
iconv._codecDataCache[codecOptions.encodingName] = codec; // Save it to be reused later. | ||
return codec; | ||
default: | ||
throw new Error("Encoding not recognized: '" + encoding + "' (searched as: '" + enc + "')"); | ||
} | ||
} | ||
}; | ||
iconv._canonicalizeEncoding = function (encoding) { | ||
// Canonicalize encoding name: strip all non-alphanumeric chars and appended year. | ||
return ('' + encoding).toLowerCase().replace(/:\d{4}$|[^0-9a-z]/g, ""); | ||
}; | ||
iconv.getEncoder = function getEncoder(encoding, options) { | ||
var codec = iconv.getCodec(encoding), | ||
encoder = new codec.encoder(options, codec); | ||
if (codec.bomAware && options && options.addBOM) encoder = new bomHandling.PrependBOM(encoder, options); | ||
return encoder; | ||
}; | ||
iconv.getDecoder = function getDecoder(encoding, options) { | ||
var codec = iconv.getCodec(encoding), | ||
decoder = new codec.decoder(options, codec); | ||
if (codec.bomAware && !(options && options.stripBOM === false)) decoder = new bomHandling.StripBOM(decoder, options); | ||
return decoder; | ||
}; // Load extensions in Node. All of them are omitted in Browserify build via 'browser' field in package.json. | ||
var nodeVer = typeof browser$1 !== 'undefined' && browser$1.versions && browser$1.versions.node; | ||
if (nodeVer) { | ||
// Load streaming support in Node v0.10+ | ||
var nodeVerArr = nodeVer.split(".").map(Number); | ||
if (nodeVerArr[0] > 0 || nodeVerArr[1] >= 10) { | ||
require("./streams")(iconv); | ||
} // Load Node primitive extensions. | ||
require("./extend-node")(iconv); | ||
} | ||
var lib = /*#__PURE__*/Object.freeze({ | ||
__proto__: null | ||
}); | ||
function getAugmentedNamespace(n) { | ||
if (n.__esModule) return n; | ||
var a = Object.defineProperty({}, '__esModule', {value: true}); | ||
Object.keys(n).forEach(function (k) { | ||
var d = Object.getOwnPropertyDescriptor(n, k); | ||
Object.defineProperty(a, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { | ||
return n[k]; | ||
} | ||
}); | ||
}); | ||
return a; | ||
} | ||
var iconv$1 = /*@__PURE__*/getAugmentedNamespace(lib); | ||
const SHIFT_JIS = 'Shift_JIS'; | ||
var lib$1 = { | ||
decode(data) { | ||
const str = iconv$1.decode(data, SHIFT_JIS); | ||
return str; | ||
}, | ||
encode(str) { | ||
const buf = iconv$1.encode(str, SHIFT_JIS); | ||
return buf; | ||
} | ||
}; | ||
/** | ||
@@ -596,7 +177,7 @@ * 内部日语用的翻译器 | ||
var buffer = uint8Array.slice(0, emptyFillIndex === -1 ? undefined : emptyFillIndex); | ||
var text = lib$1.decode(buffer); | ||
var text = shiftjis.decode(buffer); | ||
return text; | ||
} | ||
function string2buffer(text) { | ||
return lib$1.encode(text); | ||
return shiftjis.encode(text); | ||
} | ||
@@ -603,0 +184,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).Vmd={})}(this,(function(e){"use strict";function r(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function t(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function n(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}function i(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function o(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function a(e,r){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return o(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?o(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,u=!0,s=!1;return{s:function(){t=e[Symbol.iterator]()},n:function(){var e=t.next();return u=e.done,e},e:function(e){s=!0,a=e},f:function(){try{u||null==t.return||t.return()}finally{if(s)throw a}}}}var u,s={V1:"Vocaloid Motion Data file",V2:"Vocaloid Motion Data 0002"},f=(i(u={},s.V1,10),i(u,s.V2,20),u),c={int8_t:Int8Array,uint8_t:Uint8Array,int16_t:Int16Array,uint16_t:Uint16Array,int32_t:Int32Array,uint32_t:Uint32Array,float:Float32Array,double:Float64Array},h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function l(){throw new Error("setTimeout has not been defined")}function y(){throw new Error("clearTimeout has not been defined")}var d=l,m=y;function v(e){if(d===setTimeout)return setTimeout(e,0);if((d===l||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(r){try{return d.call(null,e,0)}catch(r){return d.call(this,e,0)}}}"function"==typeof h.setTimeout&&(d=setTimeout),"function"==typeof h.clearTimeout&&(m=clearTimeout);var w,g=[],p=!1,b=-1;function T(){p&&w&&(p=!1,w.length?g=w.concat(g):b=-1,g.length&&A())}function A(){if(!p){var e=v(T);p=!0;for(var r=g.length;r;){for(w=g,g=[];++b<r;)w&&w[b].run();b=-1,r=g.length}w=null,p=!1,function(e){if(m===clearTimeout)return clearTimeout(e);if((m===y||!m)&&clearTimeout)return m=clearTimeout,clearTimeout(e);try{m(e)}catch(r){try{return m.call(null,e)}catch(r){return m.call(this,e)}}}(e)}}function B(e,r){this.fun=e,this.array=r}B.prototype.run=function(){this.fun.apply(null,this.array)};function E(){}var _=E,k=E,F=E,I=E,N=E,S=E,x=E;var L=h.performance||{},O=L.now||L.mozNow||L.msNow||L.oNow||L.webkitNow||function(){return(new Date).getTime()};var C=new Date;var M={nextTick:function(e){var r=new Array(arguments.length-1);if(arguments.length>1)for(var t=1;t<arguments.length;t++)r[t-1]=arguments[t];g.push(new B(e,r)),1!==g.length||p||v(A)},title:"browser",browser:!0,env:{},argv:[],version:"",versions:{},on:_,addListener:k,once:F,off:I,removeListener:N,removeAllListeners:S,emit:x,binding:function(e){throw new Error("process.binding is not supported")},cwd:function(){return"/"},chdir:function(e){throw new Error("process.chdir is not supported")},umask:function(){return 0},hrtime:function(e){var r=.001*O.call(L),t=Math.floor(r),n=Math.floor(r%1*1e9);return e&&(t-=e[0],(n-=e[1])<0&&(t--,n+=1e9)),[t,n]},platform:"browser",release:{},config:{},uptime:function(){return(new Date-C)/1e3}},D=require("safer-buffer").Buffer,j=require("./bom-handling"),V=module.exports;V.encodings=null,V.defaultCharUnicode="�",V.defaultCharSingleByte="?",V.encode=function(e,r,t){e=""+(e||"");var n=V.getEncoder(r,t),i=n.write(e),o=n.end();return o&&o.length>0?D.concat([i,o]):i},V.decode=function(e,r,t){"string"==typeof e&&(V.skipDecodeWarning||(console.error("Iconv-lite warning: decode()-ing strings is deprecated. Refer to https://github.com/ashtuchkin/iconv-lite/wiki/Use-Buffers-when-decoding"),V.skipDecodeWarning=!0),e=D.from(""+(e||""),"binary"));var n=V.getDecoder(r,t),i=n.write(e),o=n.end();return o?i+o:i},V.encodingExists=function(e){try{return V.getCodec(e),!0}catch(e){return!1}},V.toEncoding=V.encode,V.fromEncoding=V.decode,V._codecDataCache={},V.getCodec=function(e){V.encodings||(V.encodings=require("../encodings"));for(var r=V._canonicalizeEncoding(e),t={};;){var n=V._codecDataCache[r];if(n)return n;var i=V.encodings[r];switch(typeof i){case"string":r=i;break;case"object":for(var o in i)t[o]=i[o];t.encodingName||(t.encodingName=r),r=i.type;break;case"function":return t.encodingName||(t.encodingName=r),n=new i(t,V),V._codecDataCache[t.encodingName]=n,n;default:throw new Error("Encoding not recognized: '"+e+"' (searched as: '"+r+"')")}}},V._canonicalizeEncoding=function(e){return(""+e).toLowerCase().replace(/:\d{4}$|[^0-9a-z]/g,"")},V.getEncoder=function(e,r){var t=V.getCodec(e),n=new t.encoder(r,t);return t.bomAware&&r&&r.addBOM&&(n=new j.PrependBOM(n,r)),n},V.getDecoder=function(e,r){var t=V.getCodec(e),n=new t.decoder(r,t);return!t.bomAware||r&&!1===r.stripBOM||(n=new j.StripBOM(n,r)),n};var U=void 0!==M&&M.versions&&M.versions.node;if(U){var P=U.split(".").map(Number);(P[0]>0||P[1]>=10)&&require("./streams")(V),require("./extend-node")(V)}function R(e){if(e.__esModule)return e;var r=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(e).forEach((function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})})),r}var q=R(Object.freeze({__proto__:null}));const z="Shift_JIS";var Y={decode:e=>q.decode(e,z),encode:e=>q.encode(e,z)};function X(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!e)throw new Error("length is required");return Array.from(new Array(e)).map((function(){return r}))}function Z(e){var r=new Uint8Array(e),t=r.indexOf(0),n=r.slice(0,-1===t?void 0:t);return Y.decode(n)}function W(e){return Y.encode(e)}var $=function(){function e(t){r(this,e),this.buffer=t||new ArrayBuffer(0),this.index=0}return n(e,[{key:"readArrayByConstructor",value:function(e){for(var r=this.readInt(),t=[],n=0;n<r;n++){var i=new e(this);t.push(i)}return t}},{key:"readBytes",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if("number"!=typeof e)throw new Error("readBytes failed, place check arg");if(e<=0)return"";if(this.index+e>this.buffer.byteLength)throw new Error("Stackoverflow ".concat(this.index+e," / ").concat(this.buffer.byteLength));var r=this.buffer.slice(this.index,this.index+e);return this.index=e+this.index,r}},{key:"readInt",value:function(){return this.readByType(c.uint32_t)}},{key:"readFloat",value:function(){return this.readByType(c.float)}},{key:"readString",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,r=this.readBytes(e);return Z(r)}},{key:"readByType",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,t=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(!e)throw new Error("Type is not define");var n=this.readBytes(e.BYTES_PER_ELEMENT),i=new DataView(n,0),o="get".concat(e.name.replace("Array",""));return i[o](r,t)}},{key:"readArrayByType",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:c.uint32_t,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],i=[];if(e<0)throw new Error("Invalid array length");for(var o=0;o<e;o++)i.push(this.readByType(r,t,n));return i}},{key:"close",value:function(){this.buffer=null,this.index=0}},{key:"restBytes",get:function(){return this.buffer.byteLength-this.index}}]),e}(),J=function(){function e(){r(this,e),this.bufferList=[]}return n(e,[{key:"writeTypedFrameArray",value:function(e){var r=this,t=e.length;return this.writeInt(t),e.forEach((function(e){e.writeBuffer(r)})),this}},{key:"writeBytes",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,t=new Uint8Array(Math.max(e.byteLength,r));return t.set(e),this.bufferList.push(t.buffer),this}},{key:"writeInt",value:function(e){return this.writeByType(e,c.uint32_t)}},{key:"writeFloat",value:function(e){return this.writeByType(e,c.float)}},{key:"writeString",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,t=W(e),n=new Uint8Array(r);return n.fill(253,t.length+1),n.set(t),e!==s.V1&&e!==s.V2||n.fill(0,t.length),this.bufferList.push(n.buffer),this}},{key:"writeByType",value:function(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];if(!r)throw new Error("Type is not define");var i=new DataView(new ArrayBuffer(r.BYTES_PER_ELEMENT),0),o="set".concat(r.name.replace("Array",""));return i[o](t,e,n),this.bufferList.push(i.buffer),this}},{key:"writeArrayByType",value:function(e){var r=this,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:c.uint32_t,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];if(!Array.isArray(e))throw new Error("value is not array!");return e.forEach((function(e){r.writeByType(e,t,n,i)})),this}},{key:"getArrayBuffer",value:function(){var e,r=this.bufferList.reduce((function(e,r){return e+new Uint8Array(r).length}),0),t=new Uint8Array(r),n=0,i=a(this.bufferList);try{for(i.s();!(e=i.n()).done;){var o=e.value;t.set(new Uint8Array(o),n),n+=o.byteLength}}catch(e){i.e(e)}finally{i.f()}var u=t.buffer;return this.bufferList.splice(0),u}}]),e}(),G=function(){function e(t){r(this,e),this.boneName="",this.frameTime=0,this.translation=X(3),this.rotation=X(4),this.curveX=X(16),this.curveY=X(16),this.curveZ=X(16),this.curveR=X(16),t&&(this.boneName=t.readString(15),this.frameTime=t.readInt(),this.translation=t.readArrayByType(3,c.float),this.rotation=t.readArrayByType(4,c.float),this.curveX=t.readArrayByType(16,c.uint8_t),this.curveY=t.readArrayByType(16,c.uint8_t),this.curveZ=t.readArrayByType(16,c.uint8_t),this.curveR=t.readArrayByType(16,c.uint8_t))}return n(e,[{key:"writeBuffer",value:function(e){if(!e)throw new Error("no stream!");e.writeString(this.boneName,15),e.writeInt(this.frameTime),e.writeArrayByType(this.translation,c.float),e.writeArrayByType(this.rotation,c.float),e.writeArrayByType(this.curveX,c.uint8_t),e.writeArrayByType(this.curveY,c.uint8_t),e.writeArrayByType(this.curveZ,c.uint8_t),e.writeArrayByType(this.curveR,c.uint8_t)}}]),e}(),H=function(){function e(t){r(this,e),this.frameTime=0,this.distance=0,this.position=X(3),this.rotation=X(3),this.curve=X(24),this.viewAngle=0,this.orthographic=0,t&&(this.frameTime=t.readInt(),this.distance=t.readFloat(),this.position=t.readArrayByType(3,c.float),this.rotation=t.readArrayByType(3,c.float),this.curve=t.readArrayByType(24,c.uint8_t),this.viewAngle=t.readInt(),this.orthographic=t.readInt())}return n(e,[{key:"writeBuffer",value:function(e){if(!e)throw new Error("no stream!");e.writeInt(this.frameTime),e.writeFloat(this.distance),e.writeArrayByType(this.position,c.float),e.writeArrayByType(this.rotation,c.float),e.writeInt(this.viewAngle),e.writeInt(this.orthographic)}}]),e}(),K=function(){function e(t){r(this,e),this.frameTime=0,this.rgb=[0,0,0],this.direction=[0,0,0],t&&(this.frameTime=t.readInt(),this.rgb=t.readArrayByType(3,c.float),this.direction=t.readArrayByType(3,c.float))}return n(e,[{key:"writeBuffer",value:function(e){if(!e)throw new Error("no stream!");e.writeInt(this.frameTime),e.writeArrayByType(this.rgb,c.float),e.writeArrayByType(this.direction,c.float)}}]),e}(),Q=function(){function e(t){r(this,e),this.morphName="",this.frameTime=0,this.weight=0,t&&(this.morphName=t.readString(15),this.frameTime=t.readInt(),this.weight=t.readFloat())}return n(e,[{key:"writeBuffer",value:function(e){if(!e)throw new Error("no stream!");e.writeString(this.morphName,15),e.writeInt(this.frameTime),e.writeFloat(this.weight)}}]),e}(),ee=function(){function e(t){if(r(this,e),this.version=s.V2,this.modelName="",this.boneFrames=[],this.morphFrames=[],this.cameraFrames=[],this.lightFrames=[],t){var n=new $(t);this.version=n.readString(30),this.modelName=n.readString(f[this.version]),this.boneFrames=n.readArrayByConstructor(G),this.morphFrames=n.readArrayByConstructor(Q),this.cameraFrames=n.readArrayByConstructor(H),this.lightFrames=n.readArrayByConstructor(K),n.close()}}return n(e,[{key:"write",value:function(){var e=new J;return e.writeString(this.version,30),e.writeString(this.modelName,f[this.version]),e.writeTypedFrameArray(this.boneFrames),e.writeTypedFrameArray(this.morphFrames),e.writeTypedFrameArray(this.cameraFrames),e.writeArrayByType(this.lightFrames),e.getArrayBuffer()}},{key:"timeline",get:function(){for(var e=this,r=this.boneFrames.reduce((function(e,r){var t=r.frameTime;return Math.max(e,t)}),0),t=Object.keys(this).filter((function(e){return e.includes("Frames")})),n=[],i=function(r){var i=t.reduce((function(t,n){var i=e[n];return t[n]=i.filter((function(e){return e.frameTime===r})),t}),{frameTime:r});n.push(i)},o=0;o<r;o++)i(o);return n}}]),e}();e.BONE_NAME=["センター","上半身","首","頭","左目","右目","ネクタイ1","ネクタイ2","ネクタイ3","下半身","腰飾り","左髪1","左髪2","左髪3","左髪4","左髪5","左髪6","左肩","左腕","左腕捩","左ひじ","左手捩","左手首","左袖","左親指1","左親指2","左人指1","左人指2","左人指3","左中指1","左中指2","左中指3","左薬指1","左薬指2","左薬指3","左小指1","左小指2","左小指3","左スカート前","左スカート後","左足","左ひざ","左足首","右髪1","右髪2","右髪3","右髪4","右髪5","右髪6","右肩","右腕","右腕捩","右ひじ","右手捩","右手首","右袖","右親指1","右親指2","右人指1","右人指2","右人指3","右中指1","右中指2","右中指3","右薬指1","右薬指2","右薬指3","右小指1","右小指2","右小指3","右スカート前","右スカート後","右足","右ひざ","右足首","両目","前髪1","前髪2","前髪3","左目光","右目光","ネクタイ4","左髪7","右髪7","左つま先","右つま先","ネクタイIK","左髪IK","右髪IK","左足IK","右足IK","左つま先IK","右つま先IK","下半身先","頭先","左目先","右目先","腰飾り先","左袖先","左手先","左親指先","左人差指先","左中指先","左薬指先","左小指先","左スカート前先","左スカート後先","右袖先","右手先","右親指先","右人差指先","右中指先","右薬指先","右小指先","右スカート前先","右スカート後先","センター先","両目先","ネクタイIK先","左髪IK先","右髪IK先","左足IK先","右足IK先","左つま先IK先","右つま先IK先","前髪1先","前髪2先","前髪3先","左目光先","右目光先","左腕捩先","左手捩先","右腕捩先","右手捩先","左腕捩1","左腕捩2","左腕捩3","右腕捩1","右腕捩2","右腕捩3"],e.BoneFrame=G,e.CameraFrame=H,e.LightFrame=K,e.MorphFrame=Q,e.VERSION=s,e.Vmd=ee,e.default=ee,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("shiftjis")):"function"==typeof define&&define.amd?define(["exports","shiftjis"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self).Vmd={},t.shiftjis)}(this,(function(t,r){"use strict";function e(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}function i(t,r){for(var e=0;e<r.length;e++){var i=r[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function n(t,r,e){return r&&i(t.prototype,r),e&&i(t,e),t}function a(t,r,e){return r in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function o(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,i=new Array(r);e<r;e++)i[e]=t[e];return i}function s(t,r){var e;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(e=function(t,r){if(t){if("string"==typeof t)return o(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?o(t,r):void 0}}(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var i=0,n=function(){};return{s:n,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,u=!1;return{s:function(){e=t[Symbol.iterator]()},n:function(){var t=e.next();return s=t.done,t},e:function(t){u=!0,a=t},f:function(){try{s||null==e.return||e.return()}finally{if(u)throw a}}}}var u,h={V1:"Vocaloid Motion Data file",V2:"Vocaloid Motion Data 0002"},f=(a(u={},h.V1,10),a(u,h.V2,20),u),y={int8_t:Int8Array,uint8_t:Uint8Array,int16_t:Int16Array,uint16_t:Uint16Array,int32_t:Int32Array,uint32_t:Uint32Array,float:Float32Array,double:Float64Array};function l(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!t)throw new Error("length is required");return Array.from(new Array(t)).map((function(){return r}))}function c(t){var e=new Uint8Array(t),i=e.indexOf(0),n=e.slice(0,-1===i?void 0:i);return r.decode(n)}function d(t){return r.encode(t)}var v=function(){function t(r){e(this,t),this.buffer=r||new ArrayBuffer(0),this.index=0}return n(t,[{key:"readArrayByConstructor",value:function(t){for(var r=this.readInt(),e=[],i=0;i<r;i++){var n=new t(this);e.push(n)}return e}},{key:"readBytes",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if("number"!=typeof t)throw new Error("readBytes failed, place check arg");if(t<=0)return"";if(this.index+t>this.buffer.byteLength)throw new Error("Stackoverflow ".concat(this.index+t," / ").concat(this.buffer.byteLength));var r=this.buffer.slice(this.index,this.index+t);return this.index=t+this.index,r}},{key:"readInt",value:function(){return this.readByType(y.uint32_t)}},{key:"readFloat",value:function(){return this.readByType(y.float)}},{key:"readString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,r=this.readBytes(t);return c(r)}},{key:"readByType",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,e=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(!t)throw new Error("Type is not define");var i=this.readBytes(t.BYTES_PER_ELEMENT),n=new DataView(i,0),a="get".concat(t.name.replace("Array",""));return n[a](r,e)}},{key:"readArrayByType",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:y.uint32_t,e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],n=[];if(t<0)throw new Error("Invalid array length");for(var a=0;a<t;a++)n.push(this.readByType(r,e,i));return n}},{key:"close",value:function(){this.buffer=null,this.index=0}},{key:"restBytes",get:function(){return this.buffer.byteLength-this.index}}]),t}(),m=function(){function t(){e(this,t),this.bufferList=[]}return n(t,[{key:"writeTypedFrameArray",value:function(t){var r=this,e=t.length;return this.writeInt(e),t.forEach((function(t){t.writeBuffer(r)})),this}},{key:"writeBytes",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,e=new Uint8Array(Math.max(t.byteLength,r));return e.set(t),this.bufferList.push(e.buffer),this}},{key:"writeInt",value:function(t){return this.writeByType(t,y.uint32_t)}},{key:"writeFloat",value:function(t){return this.writeByType(t,y.float)}},{key:"writeString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,e=d(t),i=new Uint8Array(r);return i.fill(253,e.length+1),i.set(e),t!==h.V1&&t!==h.V2||i.fill(0,e.length),this.bufferList.push(i.buffer),this}},{key:"writeByType",value:function(t,r){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];if(!r)throw new Error("Type is not define");var n=new DataView(new ArrayBuffer(r.BYTES_PER_ELEMENT),0),a="set".concat(r.name.replace("Array",""));return n[a](e,t,i),this.bufferList.push(n.buffer),this}},{key:"writeArrayByType",value:function(t){var r=this,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:y.uint32_t,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];if(!Array.isArray(t))throw new Error("value is not array!");return t.forEach((function(t){r.writeByType(t,e,i,n)})),this}},{key:"getArrayBuffer",value:function(){var t,r=this.bufferList.reduce((function(t,r){return t+new Uint8Array(r).length}),0),e=new Uint8Array(r),i=0,n=s(this.bufferList);try{for(n.s();!(t=n.n()).done;){var a=t.value;e.set(new Uint8Array(a),i),i+=a.byteLength}}catch(t){n.e(t)}finally{n.f()}var o=e.buffer;return this.bufferList.splice(0),o}}]),t}(),w=function(){function t(r){e(this,t),this.boneName="",this.frameTime=0,this.translation=l(3),this.rotation=l(4),this.curveX=l(16),this.curveY=l(16),this.curveZ=l(16),this.curveR=l(16),r&&(this.boneName=r.readString(15),this.frameTime=r.readInt(),this.translation=r.readArrayByType(3,y.float),this.rotation=r.readArrayByType(4,y.float),this.curveX=r.readArrayByType(16,y.uint8_t),this.curveY=r.readArrayByType(16,y.uint8_t),this.curveZ=r.readArrayByType(16,y.uint8_t),this.curveR=r.readArrayByType(16,y.uint8_t))}return n(t,[{key:"writeBuffer",value:function(t){if(!t)throw new Error("no stream!");t.writeString(this.boneName,15),t.writeInt(this.frameTime),t.writeArrayByType(this.translation,y.float),t.writeArrayByType(this.rotation,y.float),t.writeArrayByType(this.curveX,y.uint8_t),t.writeArrayByType(this.curveY,y.uint8_t),t.writeArrayByType(this.curveZ,y.uint8_t),t.writeArrayByType(this.curveR,y.uint8_t)}}]),t}(),p=function(){function t(r){e(this,t),this.frameTime=0,this.distance=0,this.position=l(3),this.rotation=l(3),this.curve=l(24),this.viewAngle=0,this.orthographic=0,r&&(this.frameTime=r.readInt(),this.distance=r.readFloat(),this.position=r.readArrayByType(3,y.float),this.rotation=r.readArrayByType(3,y.float),this.curve=r.readArrayByType(24,y.uint8_t),this.viewAngle=r.readInt(),this.orthographic=r.readInt())}return n(t,[{key:"writeBuffer",value:function(t){if(!t)throw new Error("no stream!");t.writeInt(this.frameTime),t.writeFloat(this.distance),t.writeArrayByType(this.position,y.float),t.writeArrayByType(this.rotation,y.float),t.writeInt(this.viewAngle),t.writeInt(this.orthographic)}}]),t}(),g=function(){function t(r){e(this,t),this.frameTime=0,this.rgb=[0,0,0],this.direction=[0,0,0],r&&(this.frameTime=r.readInt(),this.rgb=r.readArrayByType(3,y.float),this.direction=r.readArrayByType(3,y.float))}return n(t,[{key:"writeBuffer",value:function(t){if(!t)throw new Error("no stream!");t.writeInt(this.frameTime),t.writeArrayByType(this.rgb,y.float),t.writeArrayByType(this.direction,y.float)}}]),t}(),A=function(){function t(r){e(this,t),this.morphName="",this.frameTime=0,this.weight=0,r&&(this.morphName=r.readString(15),this.frameTime=r.readInt(),this.weight=r.readFloat())}return n(t,[{key:"writeBuffer",value:function(t){if(!t)throw new Error("no stream!");t.writeString(this.morphName,15),t.writeInt(this.frameTime),t.writeFloat(this.weight)}}]),t}(),T=function(){function t(r){if(e(this,t),this.version=h.V2,this.modelName="",this.boneFrames=[],this.morphFrames=[],this.cameraFrames=[],this.lightFrames=[],r){var i=new v(r);this.version=i.readString(30),this.modelName=i.readString(f[this.version]),this.boneFrames=i.readArrayByConstructor(w),this.morphFrames=i.readArrayByConstructor(A),this.cameraFrames=i.readArrayByConstructor(p),this.lightFrames=i.readArrayByConstructor(g),i.close()}}return n(t,[{key:"write",value:function(){var t=new m;return t.writeString(this.version,30),t.writeString(this.modelName,f[this.version]),t.writeTypedFrameArray(this.boneFrames),t.writeTypedFrameArray(this.morphFrames),t.writeTypedFrameArray(this.cameraFrames),t.writeArrayByType(this.lightFrames),t.getArrayBuffer()}},{key:"timeline",get:function(){for(var t=this,r=this.boneFrames.reduce((function(t,r){var e=r.frameTime;return Math.max(t,e)}),0),e=Object.keys(this).filter((function(t){return t.includes("Frames")})),i=[],n=function(r){var n=e.reduce((function(e,i){var n=t[i];return e[i]=n.filter((function(t){return t.frameTime===r})),e}),{frameTime:r});i.push(n)},a=0;a<r;a++)n(a);return i}}]),t}();t.BONE_NAME=["センター","上半身","首","頭","左目","右目","ネクタイ1","ネクタイ2","ネクタイ3","下半身","腰飾り","左髪1","左髪2","左髪3","左髪4","左髪5","左髪6","左肩","左腕","左腕捩","左ひじ","左手捩","左手首","左袖","左親指1","左親指2","左人指1","左人指2","左人指3","左中指1","左中指2","左中指3","左薬指1","左薬指2","左薬指3","左小指1","左小指2","左小指3","左スカート前","左スカート後","左足","左ひざ","左足首","右髪1","右髪2","右髪3","右髪4","右髪5","右髪6","右肩","右腕","右腕捩","右ひじ","右手捩","右手首","右袖","右親指1","右親指2","右人指1","右人指2","右人指3","右中指1","右中指2","右中指3","右薬指1","右薬指2","右薬指3","右小指1","右小指2","右小指3","右スカート前","右スカート後","右足","右ひざ","右足首","両目","前髪1","前髪2","前髪3","左目光","右目光","ネクタイ4","左髪7","右髪7","左つま先","右つま先","ネクタイIK","左髪IK","右髪IK","左足IK","右足IK","左つま先IK","右つま先IK","下半身先","頭先","左目先","右目先","腰飾り先","左袖先","左手先","左親指先","左人差指先","左中指先","左薬指先","左小指先","左スカート前先","左スカート後先","右袖先","右手先","右親指先","右人差指先","右中指先","右薬指先","右小指先","右スカート前先","右スカート後先","センター先","両目先","ネクタイIK先","左髪IK先","右髪IK先","左足IK先","右足IK先","左つま先IK先","右つま先IK先","前髪1先","前髪2先","前髪3先","左目光先","右目光先","左腕捩先","左手捩先","右腕捩先","右手捩先","左腕捩1","左腕捩2","左腕捩3","右腕捩1","右腕捩2","右腕捩3"],t.BoneFrame=w,t.CameraFrame=p,t.LightFrame=g,t.MorphFrame=A,t.VERSION=h,t.Vmd=T,t.default=T,Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "vmd.js", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Read and edit mmd's vmd file", | ||
@@ -35,5 +35,3 @@ "main": "dist/vmd.min.js", | ||
"@babel/preset-env": "^7.12.7", | ||
"@rollup/plugin-commonjs": "^17.0.0", | ||
"@rollup/plugin-json": "^4.1.0", | ||
"@rollup/plugin-node-resolve": "^11.0.0", | ||
"babel-preset-es2015-rollup": "^3.0.0", | ||
@@ -56,2 +54,2 @@ "eslint": "^7.15.0", | ||
] | ||
} | ||
} |
13
63404
1473