svga-compresser 1.0.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.
Files changed (2) hide show
  1. package/build/index.js +1 -0
  2. package/package.json +31 -0
package/build/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("fs"),t=require("pako"),r=require("protobufjs"),i=require("long"),n=require("tinify"),a=require("pack_textures");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var i=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,i.get?i:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,Object.freeze(t)}var l=s(t),f=o(r),p=o(i),u=o(n);function d(e,t,r,i){return new(r||(r=Promise))(function(n,a){function o(e){try{l(i.next(e))}catch(e){a(e)}}function s(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(o,s)}l((i=i.apply(e,t||[])).next())})}function y(e,t){var r,i,n,a={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=s(0),o.throw=s(1),o.return=s(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(l){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(r=1,i&&(n=2&s[0]?i.return:s[0]?i.throw||((n=i.return)&&n.call(i),0):i.next)&&!(n=n.call(i,s[1])).done)return n;switch(i=0,n&&(s=[2&s[0],n.value]),s[0]){case 0:case 1:n=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,i=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(n=a.trys,(n=n.length>0&&n[n.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!n||s[1]>n[0]&&s[1]<n[3])){a.label=s[1];break}if(6===s[0]&&a.label<n[1]){a.label=n[1],n=s;break}if(n&&a.label<n[2]){a.label=n[2],a.ops.push(s);break}n[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],i=0}finally{r=n=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}"function"==typeof SuppressedError&&SuppressedError;var c=new TextEncoder;function h(e){var t=new ArrayBuffer(8),r=new DataView(t);r.setUint32(0,1397511233,!1),r.setUint32(4,e.length,!1);for(var i=[],n=0,a=e;n<a.length;n++){var o=a[n],s=o.atlas,l=o.buffer,f=Object.keys(s),p=f.length,u=6+98*p+l.byteLength,d=new ArrayBuffer(u),y=new DataView(d),h=new Uint8Array(d),g=0;y.setUint32(g,u,!1),g+=4,y.setUint16(g,p,!1),g+=2;for(var m=0,b=f;m<b.length;m++){var v=b[m],w=s[v],E=w.x,S=w.y,A=w.w,L=w.h,x=w.ox,k=w.oy,_=w.sw,B=w.sh,O=w.ro,T=c.encode(v);y.setUint8(g,T.length),g+=1,h.set(T,g),g+=T.length,h.set(new Uint8Array(64-T.length),g),g+=64-T.length,y.setFloat32(g,E,!1),g+=4,y.setFloat32(g,S,!1),g+=4,y.setFloat32(g,A,!1),g+=4,y.setFloat32(g,L,!1),g+=4,y.setFloat32(g,x,!1),g+=4,y.setFloat32(g,k,!1),g+=4,y.setFloat32(g,_,!1),g+=4,y.setFloat32(g,B,!1),g+=4,y.setUint8(g,O?1:0),g+=1}h.set(l,g),i.push(new Uint8Array(d))}var U=8+i.reduce(function(e,t){return e+t.byteLength},0),j=new Uint8Array(U),F=0,P=function(e){j.set(e,F),F+=e.byteLength};return P(new Uint8Array(t)),i.forEach(P),j}f.default.util.Long||(f.default.util.Long=p.default,f.default.configure());var g=f.default.Root.fromJSON({nested:{com:{nested:{opensource:{nested:{svga:{options:{objc_class_prefix:"SVGAProto",java_package:"com.opensource.svgaplayer.proto"},nested:{MovieParams:{fields:{viewBoxWidth:{type:"float",id:1},viewBoxHeight:{type:"float",id:2},fps:{type:"int32",id:3},frames:{type:"int32",id:4}}},SpriteEntity:{fields:{imageKey:{type:"string",id:1},frames:{rule:"repeated",type:"FrameEntity",id:2},matteKey:{type:"string",id:3}}},AudioEntity:{fields:{audioKey:{type:"string",id:1},startFrame:{type:"int32",id:2},endFrame:{type:"int32",id:3},startTime:{type:"int32",id:4},totalTime:{type:"int32",id:5}}},Layout:{fields:{x:{type:"float",id:1},y:{type:"float",id:2},width:{type:"float",id:3},height:{type:"float",id:4}}},Transform:{fields:{a:{type:"float",id:1},b:{type:"float",id:2},c:{type:"float",id:3},d:{type:"float",id:4},tx:{type:"float",id:5},ty:{type:"float",id:6}}},ShapeEntity:{oneofs:{args:{oneof:["shape","rect","ellipse"]}},fields:{type:{type:"ShapeType",id:1},shape:{type:"ShapeArgs",id:2},rect:{type:"RectArgs",id:3},ellipse:{type:"EllipseArgs",id:4},styles:{type:"ShapeStyle",id:10},transform:{type:"Transform",id:11}},nested:{ShapeType:{values:{SHAPE:0,RECT:1,ELLIPSE:2,KEEP:3}},ShapeArgs:{fields:{d:{type:"string",id:1}}},RectArgs:{fields:{x:{type:"float",id:1},y:{type:"float",id:2},width:{type:"float",id:3},height:{type:"float",id:4},cornerRadius:{type:"float",id:5}}},EllipseArgs:{fields:{x:{type:"float",id:1},y:{type:"float",id:2},radiusX:{type:"float",id:3},radiusY:{type:"float",id:4}}},ShapeStyle:{fields:{fill:{type:"RGBAColor",id:1},stroke:{type:"RGBAColor",id:2},strokeWidth:{type:"float",id:3},lineCap:{type:"LineCap",id:4},lineJoin:{type:"LineJoin",id:5},miterLimit:{type:"float",id:6},lineDashI:{type:"float",id:7},lineDashII:{type:"float",id:8},lineDashIII:{type:"float",id:9}},nested:{RGBAColor:{fields:{r:{type:"float",id:1},g:{type:"float",id:2},b:{type:"float",id:3},a:{type:"float",id:4}}},LineCap:{values:{LineCap_BUTT:0,LineCap_ROUND:1,LineCap_SQUARE:2}},LineJoin:{values:{LineJoin_MITER:0,LineJoin_ROUND:1,LineJoin_BEVEL:2}}}}}},FrameEntity:{fields:{alpha:{type:"float",id:1},layout:{type:"Layout",id:2},transform:{type:"Transform",id:3},clipPath:{type:"string",id:4},shapes:{rule:"repeated",type:"ShapeEntity",id:5}}},MovieEntity:{fields:{version:{type:"string",id:1},params:{type:"MovieParams",id:2},images:{keyType:"string",type:"bytes",id:3},sprites:{rule:"repeated",type:"SpriteEntity",id:4},audios:{rule:"repeated",type:"AudioEntity",id:5}}}}}}}}}}}).lookupType("com.opensource.svga.MovieEntity");exports.compressSvga=function(t,r,i,n){return d(this,void 0,Promise,function(){var o,s,f,p,d,c,m,b;return y(this,function(y){switch(y.label){case 0:return[4,e.promises.readFile(t)];case 1:return o=y.sent(),s=g.decode(l.inflate(o)).toJSON(),f=s.images,r?[4,a.packTexturesByBase64OrBuffer(f)]:[3,3];case 2:return d=y.sent(),[3,4];case 3:d=Object.keys(f).map(function(e){return{name:e,buffer:Buffer.from(f[e],"base64")}}),y.label=4;case 4:return p=d,i?(u.default.key=i,[4,new Promise(function(e){u.default.validate(function(t){e(t?0:500-u.default.compressionCount)})})]):[3,8];case 5:return c=y.sent(),console.log("还剩配额:"+c),c<=p.length?(console.warn("压缩apikey:".concat(i,",配额不足")),[3,8]):[3,6];case 6:return console.log("开始压缩"),m=0,[4,Promise.all(p.map(function(e){return u.default.fromBuffer(e.buffer).toBuffer().then(function(t){console.log("压缩进度:".concat(++m,"/").concat(p.length)),e.buffer=Buffer.from(t)})}))];case 7:y.sent(),y.label=8;case 8:return r?s.images={__atlasmark__:h(p)}:p.forEach(function(e){var t=e.name,r=e.buffer;s.images[t]=r.toString("base64")}),b=l.deflate(g.encode(s).finish()),n?[4,e.promises.writeFile(n,b)]:[3,10];case 9:y.sent(),y.label=10;case 10:return[2,b]}})})};
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "svga-compresser",
3
+ "version": "1.0.1",
4
+ "main": "./build/index.js",
5
+ "scripts": {
6
+ "test": "node test/test",
7
+ "dev": "rollup -c -m -w",
8
+ "build": "rollup -c --environment BUILD:production"
9
+ },
10
+ "author": "MrKwon",
11
+ "license": "ISC",
12
+ "description": "",
13
+ "dependencies": {
14
+ "@types/pako": "^2.0.3",
15
+ "fs": "0.0.2",
16
+ "long": "^5.2.3",
17
+ "pako": "^2.1.0",
18
+ "path": "^0.12.7",
19
+ "protobufjs": "^6.8.0",
20
+ "yargs": "^12.0.5"
21
+ },
22
+ "devDependencies": {
23
+ "tinify": "^1.5.0",
24
+ "pack_textures": "^3.0.1",
25
+ "rollup": "^2.55.1",
26
+ "rollup-plugin-commonjs": "^10.1.0",
27
+ "rollup-plugin-node-resolve": "^5.2.0",
28
+ "rollup-plugin-terser": "^7.0.2",
29
+ "rollup-plugin-typescript": "^1.0.1"
30
+ }
31
+ }